-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Redefining Literal class variable in subclass has 'Incompatible type' #8796
Comments
Yup, that looks like a bug. Does it work as a workaround if you repeat the type annotation in the subclass? |
yes it does ! It also works if I overwrite foo in __init__ method for instance, and in that case no need to repeat type annotation |
Is this the same issue? from typing import Generic, List, Literal, TypeVar
T = TypeVar("T", bound=str)
class Thing(Generic[T]):
collection: List[T]
word: T
class SubThing(Thing[Literal["word"]]):
collection = ["word"]
word = "word"
Mypy seems happy with the py == 3.8.5 |
Ditto with
and no additional flags. |
Just ran into this issue with 0.910. |
there's still the same problem 0.930 |
Also ran into this bug with version |
Is this fixed? Still running into this issue in |
This was fixed in 57de8db which isn't in 0.982. |
Ah makes sense, thank you! |
Are you reporting a bug, or opening a feature request?
Bug
Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
What is the actual behavior/output?
What is the behavior/output you expect?
I expected no error, as
B.foo
is still of typeLiteral['bar', 'spam']
What are the versions of mypy and Python you are using?
mypy == 0.770
Python == 3.8
What are the mypy flags you are using? (For example --strict-optional)
no flags
The text was updated successfully, but these errors were encountered: