-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
classmethod and selftype: incompatible with supertype #2511
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
Comments
This is a known issue with self types: #2353 |
Closed as duplicate. |
I think this is not a duplicate of #2353. In that issue mypy allows unsafe override, while here mypy prohibits a safe override. Also this example is specific to |
Still seeing this with mypy 0.670 |
#7401 has a slightly different example (no annotation for |
#7466 looks like yet another duplicate. Raising priority to high, since this started to come up more often and a fix might be not hard. |
I am defining some classes capable of returning an (optional) instance of themselves based on a configuration (a dictionary).
In the base class I use the new SelfType capability to define the generic classmethod. I wanted to use a metaclass with abc.abstractclassmethod but mypy doesn't seem to support that.
In the subclass I now use the narrower type for cls and the return value but mypy gives me an error:
repro.py:
I could only make it work by defining B like this which looks quite ugly and requires passing around the type variable:
Is that the intended result?
The text was updated successfully, but these errors were encountered: