Skip to content

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

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

Conversation

ilevkivskyi
Copy link
Member

Fixes #6700

This is another followup for the checkmember work. Currently, we only support non-instance method aliasing in few very specific cases. I am making this support general.

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

antidote (https://github.com/Finistere/antidote)
+ tests/core/test_inject_wrapper.py:228: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/core/test_inject_wrapper.py:234: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/core/test_inject_wrapper.py:240: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/core/test_inject_wrapper.py:336: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/core/test_inject_wrapper.py:342: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/core/test_inject_wrapper.py:348: error: Unused "type: ignore" comment  [unused-ignore]

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Nice, this fixes a highly-upvoted issue. Looks good, left some minor comments.


reveal_type(A().g) # N: Revealed type is "builtins.int"
reveal_type(A().g2) # N: Revealed type is "builtins.int"
A().g2 = 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Test assignment to A().g (should generate an error).

def foo2(cls, x):
...

bar2 = foo2
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

@@ -8531,15 +8545,21 @@ def visit_type_alias_type(self, t: TypeAliasType) -> Type:
return t.copy_modified(args=[a.accept(self) for a in t.args])


def is_node_class(node: Node | None) -> bool | None:
Copy link
Collaborator

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_node or similar? My initial thought what that this checks if the target is a "node class".

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

Successfully merging this pull request may close these issues.

Property, classmethod and staticmethod aliases not supported
2 participants