Skip to content

Commit 107ede7

Browse files
committed
Some more tests
1 parent 97534e4 commit 107ede7

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

test-data/unit/check-classes.test

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7677,10 +7677,13 @@ class A:
76777677

76787678
T = TypeVar("T")
76797679
def foo(f: Callable[[], T]) -> T: ...
7680+
def bar(t: type[T]) -> T: ...
76807681

76817682
ta: type[A]
76827683
reveal_type(foo(A)) # N: Revealed type is "builtins.int"
76837684
reveal_type(foo(ta)) # N: Revealed type is "builtins.int"
7685+
reveal_type(bar(A)) # N: Revealed type is "__main__.A"
7686+
reveal_type(bar(ta)) # N: Revealed type is "__main__.A"
76847687

76857688
[case testNewReturnTypeCallableNarrowing]
76867689
from typing import Callable, TypeVar
@@ -7700,6 +7703,40 @@ if issubclass(tx, B):
77007703
reveal_type(tx) # N: Revealed type is "type[__main__.B]"
77017704
[builtins fixtures/isinstancelist.pyi]
77027705

7706+
[case testNewReturnTypeOverloadNarrowing]
7707+
from typing import TypeVar, Generic, Union, overload
7708+
7709+
T = TypeVar("T", int, str)
7710+
7711+
class Series(Generic[T]):
7712+
@overload
7713+
def __new__(cls, dtype: int) -> IntSeries: ...
7714+
@overload
7715+
def __new__(cls, dtype: type[T]) -> Series[T]: ...
7716+
@overload
7717+
def __new__(cls, dtype=...) -> Series: ...
7718+
def __new__(cls, dtype=...) -> Series:
7719+
...
7720+
7721+
class IntSeries(Series[int]): ...
7722+
7723+
class Index:
7724+
@overload
7725+
def __new__(cls, dtype: int) -> IntIndex: ...
7726+
@overload
7727+
def __new__(cls, dtype=...) -> Index: ...
7728+
def __new__(cls, dtype=...) -> Index:
7729+
...
7730+
7731+
class IntIndex(Index): ...
7732+
7733+
def foo(x: Union[Series, int, Index]):
7734+
if isinstance(x, (Series, Index)):
7735+
reveal_type(x) # N: Revealed type is "__main__.Series[Any] | __main__.Index"
7736+
else:
7737+
reveal_type(x) # N: Revealed type is "builtins.int"
7738+
[builtins fixtures/isinstancelist.pyi]
7739+
77037740
[case testMetaclassPlaceholderNode]
77047741
from sympy.assumptions import ManagedProperties
77057742
from sympy.ops import AssocOp

0 commit comments

Comments
 (0)