Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Viicos
Copy link
Contributor

@Viicos Viicos commented Dec 23, 2024

Fixes #18323.
Follow up on #18090.

Notes:

  • In analyze_descriptor_access, there is a distinction between typ and descriptor_type:

    mypy/mypy/checkmember.py

    Lines 687 to 688 in 9ff9946

    typ = map_instance_to_supertype(descriptor_type, dunder_get.info)
    dunder_get_type = expand_type_by_instance(bound_method, typ)
    it seems that in our case though, map_instance_to_supertype returns descriptor_type unchanged. The reason I'm mentioning this is that expand_type_by_instance uses typ and not descriptor_type. In warn_deprecated_overload_item, we have access to descriptor_type (passed as selftype):

    mypy/mypy/checkmember.py

    Lines 726 to 728 in 9ff9946

    mx.chk.warn_deprecated_overload_item(
    dunder_get, mx.context, target=inferred_dunder_get_type, selftype=descriptor_type
    )
    and in this changeset I call expand_type_by_instance(candidate, selftype). Is this going to be an issue?
  • To comply with the type checker, I had to change the type annotation of selftype to Instance. Is this going to be an issue?

This comment has been minimized.

@Viicos Viicos force-pushed the deprecated-generic-descriptors branch from 3e0684b to 8ca2a14 Compare December 23, 2024 21:48
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@brianschubert brianschubert added the topic-pep-702 PEP 702, @deprecated label Dec 23, 2024
@@ -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(
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-pep-702 PEP 702, @deprecated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generic descriptors with a deprecated __get__ overload
3 participants