Repository navigation
fix foo = classmethod(foo) does not create a working classmethod #3362 - #4796
asukaminato0721 wants to merge 3 commits into
Conversation
|
This pull request has been imported. If you are a Meta employee, you can view this in D118597715. (Because this pull request was imported automatically, there will not be any future comments.) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
stroxler
left a comment
There was a problem hiding this comment.
This needs a rebase before we can merge it, since it has build failures.
In addition, there are some behavior issues:
- Wrong-scope lookup: an inner class’s
f = classmethod(f)can mark an unrelated outer-class method.Outer().f()then incorrectly inferstype[Outer]instead ofOuter. - Aliases change retroactively: saving
g = fbefore wrappingfalso convertsg’s inferred behavior to a classmethod, although it remains an instance method at runtime. - Decorator composition breaks: the flag changes the undecorated function’s receiver before existing decorators run. A valid adapter from an instance-taking function to a class-taking callable gains a false-positive argument error.
- Overloads become inconsistent: only the implementation is marked, producing new
invalid-overloaderrors on otherwise valid overload declarations.
This comment has been minimized.
This comment has been minimized.
stroxler
left a comment
There was a problem hiding this comment.
Thanks! I think the first round of review notes are closed out. A second round flagged a few more concerns we should probably address before we merge:
- Captured defaults are still retyped retroactively. Saving the original method in another method’s parameter default produces a false signature error after wrapping.
- Receiver-dependent inference breaks. An aliased method delegating to another classmethod can infer
type[type[A]]instead oftype[A]; the generic variant loses its return type toUnknown. - Defaulted type parameters trigger a false error. The synthetic
Receiveris validated after a defaulted user parameter, producing an ordering diagnostic for a parameter the user never wrote.
This comment has been minimized.
This comment has been minimized.
stroxler
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
Land bounced due to a merge conflict. I think there's a periodic job that will pop up a tool where I can fix it manually |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
This pull request has been merged in e9544b0. |
Summary
Fixes #3362
Recognizes
f = classmethod(f)during binding and types cls astype[Self], preserves subclass-aware return inference and class-attribute initialization, avoids triggering when classmethod is shadowed.Test Plan
add test