-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Generalize class/static method and property alias support #19297
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -587,6 +587,53 @@ class C(B): | |
| class B: ... | ||
| [builtins fixtures/classmethod.pyi] | ||
|
|
||
| [case testClassMethodAliasInClass] | ||
| from typing import overload | ||
|
|
||
| class C: | ||
| @classmethod | ||
| def foo(cls) -> int: ... | ||
|
|
||
| bar = foo | ||
|
|
||
| @overload | ||
| @classmethod | ||
| def foo2(cls, x: int) -> int: ... | ||
| @overload | ||
| @classmethod | ||
| def foo2(cls, x: str) -> str: ... | ||
| @classmethod | ||
| def foo2(cls, x): | ||
| ... | ||
|
|
||
| bar2 = foo2 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth it to also test static methods? Did they already work?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static methods already worked, but not overloaded ones. I added a test specifically for overloaded static method. |
||
|
|
||
| reveal_type(C.bar) # N: Revealed type is "def () -> builtins.int" | ||
| reveal_type(C().bar) # N: Revealed type is "def () -> builtins.int" | ||
| reveal_type(C.bar2) # N: Revealed type is "Overload(def (x: builtins.int) -> builtins.int, def (x: builtins.str) -> builtins.str)" | ||
| reveal_type(C().bar2) # N: Revealed type is "Overload(def (x: builtins.int) -> builtins.int, def (x: builtins.str) -> builtins.str)" | ||
| [builtins fixtures/classmethod.pyi] | ||
|
|
||
| [case testPropertyAliasInClassBody] | ||
| class A: | ||
| @property | ||
| def f(self) -> int: ... | ||
|
|
||
| g = f | ||
|
|
||
| @property | ||
| def f2(self) -> int: ... | ||
| @f2.setter | ||
| def f2(self, val: int) -> None: ... | ||
|
|
||
| g2 = f2 | ||
|
|
||
| reveal_type(A().g) # N: Revealed type is "builtins.int" | ||
| reveal_type(A().g2) # N: Revealed type is "builtins.int" | ||
| A().g2 = 1 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test assignment to |
||
| A().g2 = "no" # E: Incompatible types in assignment (expression has type "str", variable has type "int") | ||
| [builtins fixtures/property.pyi] | ||
|
|
||
| [case testCallableUnionCallback] | ||
| from typing import Union, Callable, TypeVar | ||
|
|
||
|
|
||
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.
Nit: Maybe rename to
is_classmethod_nodeor similar? My initial thought what that this checks if the target is a "node class".