KEMBAR78
Generalize class/static method and property alias support by ilevkivskyi · Pull Request #19297 · python/mypy · GitHub
Skip to content

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.

@github-actions

This comment has been minimized.

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

mypy/checker.py Outdated
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".

@github-actions
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]

@ilevkivskyi ilevkivskyi merged commit 9f455bd into python:master Jun 18, 2025
19 checks passed
@ilevkivskyi ilevkivskyi deleted the classmethod-alias branch June 18, 2025 23:23
ilevkivskyi pushed a commit that referenced this pull request Aug 2, 2025
Closes #19509

Bisect show that the issue was fixed by #19297
dangotbanned added a commit to narwhals-dev/narwhals that referenced this pull request Aug 10, 2025
`from_modin` alias *should* type check okay after release w/ (python/mypy#19297)

Keeping as-is, since `pyright` understands and `pylance` can re-use the docstring
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