-
-
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
Correctly handle cls in protocol classmethod #11119
Correctly handle cls in protocol classmethod #11119
Conversation
T = TypeVar('T') | ||
|
||
class HasDoX(Protocol): | ||
@classmethod |
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.
What about @staticmethod
? Does it fall into the same problem?
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.
staticmethod doesn't have this problem, because there's no self/cls to bind
mypy/subtypes.py
Outdated
@@ -710,7 +710,7 @@ def find_node_type(node: Union[Var, FuncBase], itype: Instance, subtype: Type) - | |||
and node.is_initialized_in_class | |||
and not node.is_staticmethod)): | |||
assert isinstance(typ, FunctionLike) | |||
signature = bind_self(typ, subtype) | |||
signature = bind_self(typ, subtype, isinstance(node, Var) and node.is_classmethod) |
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 think that adding argument name here would be better for readability.
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.
@sobolevn I've added argument name here, is there anything else I can do?
Closes python#11115. Correctly handle cls in generic classmethods of protocol. This should correctly handle cls in classmethods. Current behavior of not passing is_classmethod seems like an omission in implementation, so this should only correct buggy behavior and shouldn't break something else. Adds a test case `testSelfTypeProtocolClassmethodMatch`.
Description
Correctly handle cls in generic classmethods of protocol. Closes #11115
This should correctly handle cls in classmethods. Current behavior of not passing is_classmethod seems like an omission in implementation, so this should only correct buggy behavior and shouldn't break something else.
Test Plan
I've included a test in the test suite (testSelfTypeProtocolClassmethodMatch)