-
-
Couldn't load subscription status.
- Fork 3k
Description
I have a class that inherits from Generic[T], where is T = TypeVar("T", A, B).
When feeding in A or B, mypy raises no errors. However, when feeding in a subclass of A (called ASub), mypy errors.
In my opinion, mypy should not error when feeding in a subclass. I believe this is a bug.
Here is sample code necessary to reproduce what I am seeing.
from typing import Union, TypeVar, Generic
class A:
pass
class ASub(A):
pass
class B:
pass
# Case 1... Success: no issues found
# T = TypeVar("T", bound=Union[A, B])
# Case 2... error: Value of type variable "T" of "SomeGeneric" cannot be "ASub"
T = TypeVar("T", A, B)
class SomeGeneric(Generic[T]):
pass
class SomeGenericASub(SomeGeneric[ASub]):
passI included the Union case as a comment to highlight that for some reason, Union doesn't raise an error. However, I don't see why it should not error, when using just A, B does error
I am invoking mypy from the command line with no flags. Here are my versions:
python==3.6.5
mypy==0.770
Aside
I encountered this issue, and then discovered the "minimal repro" was already asked in Stack Overflow here. However, the answer provided did not actually solve the problem, so I think this is a bug in mypy.
I apologize in advance if this is a duplicate issue.