You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
fromtypingimportUnion, TypeVar, GenericclassA:
passclassASub(A):
passclassB:
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)
classSomeGeneric(Generic[T]):
passclassSomeGenericASub(SomeGeneric[ASub]):
pass
I 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.
The text was updated successfully, but these errors were encountered:
Yeah I think this seems like a bug. Probably not too hard to fix if you want to submit a PR. Looks like check_type_var_values in semanal_typeargs.py is the culprit.
This sort of constrained type variable is usually best avoided, though, except when it is absolutely necessary.
I have a class that inherits from
Generic[T]
, where isT = TypeVar("T", A, B)
.When feeding in
A
orB
, mypy raises no errors. However, when feeding in a subclass ofA
(calledASub
), 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.
I 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 justA, B
does errorI am invoking mypy from the command line with no flags. Here are my versions:
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.
The text was updated successfully, but these errors were encountered: