-
Notifications
You must be signed in to change notification settings - Fork 771
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
Factory class methods that return instance are hinted incorrectly when called explicitly from subclass #395
Comments
Thanks for the bug report. You are correct. Pylance was not correctly handling the second argument of the two-argument form of the |
This issue has been fixed in version 2020.9.6, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202096-23-september-2020 |
I confirm this works (with 2021.3.0 now) But this looks to me like a workaround -- why do we need to explicitly bind and annotate Without it, pylance inferred type for My very similar motivating example: class A:
@classmethod
def factory(cls):
return cls()
class B(A):
def methodB(self):
pass
B().factory().methodB() Output: Cannot access member "methodB" for class "A" |
Internally, Pylance synthesizes generic types for As for the return type of the |
Environment data
Expected behaviour
Having a class method that returns an instance of the class, if the class method is called from the subclass the type hint should be the subclass.
Actual behaviour
The type hint is the super class, where the class method is defined.
Code Snippet / Additional information
Here is a trivial example that shows the issue.
What I am trying to do is actually override the class method and call the super class one with additional arguments. But I noticed calling the class method of the super class explicitly type hints incorrectly.
The text was updated successfully, but these errors were encountered: