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
So I have a base class with a class attribute of type tuple[str, ...], I expect that deriving from this base class and assigning a concrete value should be fine.
However, mypy narrows the type of Concrete.x to tuple[str], and then if I try and derive from Concrete, tuple[str, str] is incompatible with tuple[str], so I can't assign a two-tuple to the class attribute in Derived.
Now, if the type of xreally weretuple[str], this would be fine. But I think I've explicitly said "it's a tuple of any length", and both ("foo",) and ("foo", "bar") satisfy is-a tuple[str, ...].
Expected Behavior
I expect mypy to use the type annotation I've provided on the base class, and maintain that the type of x is always tuple[str, ...].
Output
main.py:10: error: Incompatible types in assignment (expression has type "tuple[str, str]", base class "Concrete" defined the type as "tuple[str]") [assignment]
main.py:13: note: Revealed type is "builtins.tuple[builtins.str, ...]"
main.py:14: note: Revealed type is "tuple[builtins.str]"
main.py:15: error: Cannot determine type of "x" [has-type]
main.py:15: note: Revealed type is "Any"
Found 2 errors in 1 file (checked 1 source file)
The text was updated successfully, but these errors were encountered:
Bug Report
Consider (https://mypy-play.net/?mypy=latest&python=3.12&gist=8afb9e0642a24aad8c26f3d22045ce18)
So I have a base class with a class attribute of type
tuple[str, ...]
, I expect that deriving from this base class and assigning a concrete value should be fine.However, mypy narrows the type of
Concrete.x
totuple[str]
, and then if I try and derive fromConcrete
,tuple[str, str]
is incompatible withtuple[str]
, so I can't assign a two-tuple to the class attribute inDerived
.Now, if the type of
x
really weretuple[str]
, this would be fine. But I think I've explicitly said "it's a tuple of any length", and both("foo",)
and("foo", "bar")
satisfyis-a tuple[str, ...]
.Expected Behavior
I expect mypy to use the type annotation I've provided on the base class, and maintain that the type of
x
is alwaystuple[str, ...]
.Output
The text was updated successfully, but these errors were encountered: