Skip to content

Commit bcd0480

Browse files
authored
New semantic analyzer: add tests for casts and type application (python#6566)
It seems like they already work fine? Closes python#6291, python#6292.
1 parent c953bb6 commit bcd0480

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

test-data/unit/check-newsemanal.test

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,8 @@ strict_optional = True
15401540
[[mypy-b]
15411541
strict_optional = False
15421542

1543+
-- ]]
1544+
15431545
[case testNewAnalyzerProperty]
15441546
class A:
15451547
@property
@@ -1920,3 +1922,78 @@ reveal_type(y[0]) # E: Revealed type is 'builtins.int'
19201922
x: A
19211923
reveal_type(x) # E: Revealed type is '__main__.G[Tuple[builtins.int, fallback=__main__.C]]'
19221924
[builtins fixtures/list.pyi]
1925+
1926+
[case testNewAnalyzerCastForward1]
1927+
from typing import cast
1928+
1929+
x = cast('C', None)
1930+
class A:
1931+
def foo(self) -> None:
1932+
self.x = cast('C', None)
1933+
1934+
reveal_type(x) # E: Revealed type is '__main__.C'
1935+
reveal_type(A().x) # E: Revealed type is '__main__.C'
1936+
1937+
class C(A): ...
1938+
1939+
[case testNewAnalyzerCastForward2]
1940+
from typing import cast
1941+
1942+
x = cast('C', None)
1943+
1944+
reveal_type(x) # E: Revealed type is 'builtins.int'
1945+
1946+
C = int
1947+
1948+
[case testNewAnalyzerCastForward2]
1949+
from typing import cast, NamedTuple
1950+
1951+
x = cast('C', None)
1952+
1953+
reveal_type(x) # E: Revealed type is 'Tuple[builtins.int, fallback=__main__.C]'
1954+
reveal_type(x.x) # E: Revealed type is 'builtins.int'
1955+
1956+
C = NamedTuple('C', [('x', int)])
1957+
1958+
[case testNewAnalyzerApplicationForward1]
1959+
from typing import Generic, TypeVar
1960+
1961+
x = C[int]()
1962+
reveal_type(x) # E: Revealed type is '__main__.C[builtins.int*]'
1963+
1964+
T = TypeVar('T')
1965+
class C(Generic[T]): ...
1966+
1967+
[case testNewAnalyzerApplicationForward2]
1968+
from typing import Generic, TypeVar
1969+
1970+
T = TypeVar('T')
1971+
class C(Generic[T]): ...
1972+
1973+
x = C['A']()
1974+
reveal_type(x) # E: Revealed type is '__main__.C[__main__.A*]'
1975+
1976+
class A: ...
1977+
1978+
[case testNewAnalyzerApplicationForward3]
1979+
from typing import Generic, TypeVar
1980+
1981+
x = C[A]()
1982+
reveal_type(x) # E: Revealed type is '__main__.C[__main__.A*]'
1983+
1984+
T = TypeVar('T')
1985+
class C(Generic[T]): ...
1986+
1987+
class A: ...
1988+
1989+
[case testNewAnalyzerApplicationForward4]
1990+
from typing import Generic, TypeVar
1991+
1992+
x = C[A]() # E: Value of type variable "T" of "C" cannot be "A"
1993+
reveal_type(x) # E: Revealed type is '__main__.C[__main__.A*]'
1994+
1995+
T = TypeVar('T', bound='D')
1996+
class C(Generic[T]): ...
1997+
1998+
class A: ...
1999+
class D: ...

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy