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
{{ message }}
Repository navigation
TypeVar bound to Union in if isinstance(...) branch has incompatible return type #12800
A TypeVar bound to Union[x, y] will resolve to x after an if isinstance(..., x) is used which is incompatible with the return type.
I'm not sure on how to describe exactly what is going on, better check the Example.
Also mypy experts, please forgive me if that is intended behavior and not a bug (I would appreciate a working solution in this case :)
Gives T`-1 three times and no error. But I just add None which is not a member of T bounds, so it shouldn't affect inference, right?.. Say, the following ignores None in similar case:
Activity
headtr1ck commentedon May 16, 2022
As a side note: a
reveal_type(x)in the else branch returns"T`-1". Maybe a more expressive type would be useful?AlexWaygood commentedon May 16, 2022
This one looks like a bug to me :)
For a (horrible) workaround, you can use overloads instead:
sterliakov commentedon May 17, 2022
I don't know what does it mean for debugging, but this is also a bit odd:
Gives
T`-1,strandT`-1revealed (in order) and error on line 9 (1st return). However, the following:Gives
T`-1three times and no error. But I just addNonewhich is not a member ofTbounds, so it shouldn't affect inference, right?.. Say, the following ignoresNonein similar case:But... Maybe it should be a separate issue, given this weird result with
mypyfrom master and python 3.10:AlexWaygood commentedon May 17, 2022
@headtr1ck, a slightly simpler and less horrible workaround: just use a
cast():headtr1ck commentedon May 17, 2022
This is what I ended up doing in the moment.
gschaffner commentedon Oct 13, 2022
Is this a duplicate of #10817?
hauntsaninja commentedon Jan 10, 2023
Closing as duplicate of #10817
moranabadie commentedon Jun 25, 2024
#10817 is closed but the problem persists in python 1.10.1
AlexWaygood commentedon Jun 25, 2024
not true, it is still open