-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fixes #1727: constructor after classmethod counts #5501
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
Conversation
Possibly, another solution is to do what |
Also, I don't quite like |
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.
Thanks! This is an important issue to fix, but there are some potential dangers. I believe the right fix should also fix #4575 The underlying problem is the same: processing of class method signatures happens too soon.
Also the current solution has the problem that it might not work well with the fine grained daemon (because class is not a "real" fine-grained dependency target). Probably, I would move this step to the patches after third pass (at least after forward refs are resolved) unless there are some other problems.
Also please note many mypy core devs are on vacation now, so we may not always respond in time. I am only leaving "large scale" comments now.
self._arg: int = arg | ||
|
||
reveal_type(C.create) # E: Revealed type is 'def (arg: builtins.int) -> __main__.C' | ||
[builtins fixtures/classmethod.pyi] |
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 am not sure this test actually tests the situation enough. I think what you need to add is a reveal_type
for cls
and cls(<expected args>)
in the method body, and as well check that cls(<unexpected args>)
fails with a reasonable error.
Please be sure to include all the examples that appeared in the original issue. In addition please add at least tests that check your fix works correctly with the following:
- Fine-grained daemon
- Forward references
- Generic classes
- Overloaded methods (there are known issues, but few simple tests would help)
mypy/semanal.py
Outdated
functype = func.type | ||
assert self.type | ||
assert functype | ||
assert isinstance(functype, CallableType) |
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.
Why do you need these asserts? Please add assert messages.
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.
That was basically to make mypy
happy of this code. Fixed to make more sense.
Thanks for the review, I'll try to fix all the issues as soon as possible. |
Constructor defined after classmethod was considered to have no args in the classmethod. This commit fixes that bug.
b39eb0f
to
d5ed26a
Compare
I believe that's all tests we reasonably need. |
Hmm is this now superseded by #5646? Thanks for getting the ball rolling with this anyway! |
Yes, I think now that we have a broader fix, this one is not needed. Closing in favor of #5646 @VadimPushtaev Thank you for working on this! |
This is a fix for #1727.
Instead of prepare classmethod definitions while analyzing class, let's postpone this until the class is fully analyzed.
dataclass
magic creates__init__
after the class is already created, so they fix up all the classmethods. This is no longer needed.