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
Generic type incorrectly un-narrowed following TypeIs #19282
from typing_extensions import Any, TypeIs, reveal_type
class C[T]:
v: T
def is_int(v: object) -> TypeIs[C[int]]: ...
def f(c: C[Any]):
if is_int(c):
reveal_type(c)
reveal_type(c) # should be C[Any], but is C[int]
fromtyping_extensionsimportAny, TypeIs, reveal_typeclassC[T]:
v: Tdefis_int(v: object) ->TypeIs[C[int]]: ...
deff(c: C[Any]) ->None:
ifis_int(c):
reveal_type(c) # N: Revealed type is "__main__.C[builtins.int]"else:
reveal_type(c) # E: Statement is unreachable [unreachable]reveal_type(c) # N: Revealed type is "__main__.C[builtins.int]"
C[Any] can definitely be some C that is not C[int]! These two problems have the same cause - "implicit" else was unreachable, so the binder narrowed c to union of reachable branches.
Activity
sterliakov commentedon Jun 12, 2025
Even worse,
C[Any]can definitely be someCthat is notC[int]! These two problems have the same cause - "implicit"elsewas unreachable, so the binder narrowedcto union of reachable branches.brianschubert commentedon Jun 12, 2025
Is this the same as #18009?
brianschubert commentedon Jun 12, 2025
It seems #18193 fixes this, I'll see about picking that back up
Fix `TypeIs` negative narrowing of union of generics (#18193)