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

PEP 702 (@deprecated): "normal" overloaded methods #18477

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

tyralla
Copy link
Collaborator

@tyralla tyralla commented Jan 15, 2025

Fixes #18474

It seems I covered overloaded functions, descriptors, and special methods so far but completely forgot about "normal" methods (thanks to @sobolevn for pointing this out). This addition should do the trick.

tyralla and others added 2 commits January 15, 2025 21:38
Fixes python#18474

It seems I covered overloaded functions, descriptors, and special methods so far but completely forgot about "normal" methods (thanks to @sobolevn for pointing this out).  This addition should do the trick.
@cdce8p cdce8p added topic-pep-702 PEP 702, @deprecated topic-overloads labels Jan 15, 2025

This comment has been minimized.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! What about @staticmethod and @classmethod?

Comment on lines 1490 to 1493
(node is None)
and (member is not None)
and isinstance(object_type, Instance)
and ((symbol := object_type.type.names.get(member)) is not None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(node is None)
and (member is not None)
and isinstance(object_type, Instance)
and ((symbol := object_type.type.names.get(member)) is not None)
node is None
and member is not None
and isinstance(object_type, Instance)
and (symbol := object_type.type.names.get(member)) is not None

Copy link
Collaborator Author

@tyralla tyralla Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have a look at it later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It became a one-liner followed by a loop.

@tyralla
Copy link
Collaborator Author

tyralla commented Jan 16, 2025

Inheritance is also an issue: If the (overloaded) function is defined by a base class of object_type, object_type.type.names.get(member) cannot work.

The base class is not directly available. Going through the MRO might be necessary (at least for static methods).

…ods' into narrowing/overloaded_normal_methods

# Conflicts:
#	mypy/checkexpr.py
@tyralla
Copy link
Collaborator Author

tyralla commented Jan 17, 2025

@sobolevn: classmethod already worked, staticmethod not (needed to skip bind_self). Inheritance now also works. Searching through the MRO makes it even nastier, in my opinion, but I found no other place where all information is directly available.

This comment has been minimized.

@tyralla tyralla requested a review from sobolevn January 17, 2025 17:53
test-data/unit/check-deprecated.test Outdated Show resolved Hide resolved
@classmethod
def h(self, v: Union[int, str]) -> A: ...

class B(A): ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also test that A can have regular method overriden with B with deprecated case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not really necessary. Unless you suggest not reporting a deprecation warning if a base class offers a corresponding not deprecated method. This seems somehow related to #18085, which has not received a response so far. Maybe, because it is a little confusing. Or because the topic confused me...

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overloaded deprecated method use is not reported
3 participants