@@ -2739,3 +2739,34 @@ def foo(x: dict[str, Any]) -> bool:
27392739 return True
27402740 raise
27412741[builtins fixtures/dict.pyi]
2742+
2743+
2744+ [case testNarrowingTypeObjects]
2745+ from __future__ import annotations
2746+ from typing import Callable, Any, TypeVar, Generic, Protocol
2747+ _T_co = TypeVar('_T_co', covariant=True)
2748+
2749+ class Boxxy(Protocol[_T_co]):
2750+ def get_box(self) -> _T_co: ...
2751+
2752+ class TupleLike(Generic[_T_co]):
2753+ def __init__(self, iterable: Boxxy[_T_co], /) -> None:
2754+ raise
2755+
2756+ class Box1(Generic[_T_co]):
2757+ def __init__(self, content: _T_co, /) -> None: ...
2758+ def get_box(self) -> _T_co: raise
2759+
2760+ class Box2(Generic[_T_co]):
2761+ def __init__(self, content: _T_co, /) -> None: ...
2762+ def get_box(self) -> _T_co: raise
2763+
2764+ def get_type(setting_name: str) -> Callable[[Box1], Any] | type[Any]:
2765+ raise
2766+
2767+ def main(key: str):
2768+ existing_value_type = get_type(key)
2769+ if existing_value_type is TupleLike:
2770+ reveal_type(TupleLike) # N: Revealed type is "(def (__main__.Box1[Any]) -> Any) | type[Any]"
2771+ TupleLike(Box2("str")) # E: Argument 1 has incompatible type "Box2[str]"; expected "Box1[Any]"
2772+ [builtins fixtures/tuple.pyi]
0 commit comments