-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support @deprecated()
on overloaded __get__
for generic descriptors
#18333
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
3e0684b
to
8ca2a14
Compare
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
@@ -7724,7 +7729,9 @@ def warn_deprecated_overload_item( | |||
candidate := item.func.type, CallableType | |||
): | |||
if selftype is not None: | |||
candidate = bind_self(candidate, selftype) | |||
candidate = bind_self( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit surprised about this bind_self
, actually. I cannot find where inferred_dunder_get_type
gets passed to bind_self
... I'm only looking at the code though. I'm certain it's used but... where?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, in analyze_descriptor_access
, we pass inferred_dunder_get_type
as target
:
Lines 726 to 728 in 9ff9946
mx.chk.warn_deprecated_overload_item( | |
dunder_get, mx.context, target=inferred_dunder_get_type, selftype=descriptor_type | |
) |
but not sure what you mean exactly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I'd expect some sort of symmetry: we repeat the actions we did to get target on each overload member. But I can't find where we bind_self
.
To be specific, in analyze_descriptor_access
(or in a function it calls) I expect a bind_self
call as dunder_get
turns into inferred_dunder_get_type
... but I can't find one. Is it just not necessary?
Fixes #18323.
Follow up on #18090.
Notes:
analyze_descriptor_access
, there is a distinction betweentyp
anddescriptor_type
:mypy/mypy/checkmember.py
Lines 687 to 688 in 9ff9946
map_instance_to_supertype
returnsdescriptor_type
unchanged. The reason I'm mentioning this is thatexpand_type_by_instance
usestyp
and notdescriptor_type
. Inwarn_deprecated_overload_item
, we have access todescriptor_type
(passed asselftype
):mypy/mypy/checkmember.py
Lines 726 to 728 in 9ff9946
expand_type_by_instance(candidate, selftype)
. Is this going to be an issue?selftype
toInstance
. Is this going to be an issue?