@@ -1663,7 +1663,7 @@ _testNarrowTypeForDictKeys.py:16: note: Revealed type is "Union[builtins.str, No
1663
1663
1664
1664
[case testTypeAliasWithNewStyleUnion]
1665
1665
# flags: --python-version 3.10
1666
- from typing import Literal, Type, TypeAlias
1666
+ from typing import Literal, Type, TypeAlias, TypeVar
1667
1667
1668
1668
Foo = Literal[1, 2]
1669
1669
reveal_type(Foo)
@@ -1682,15 +1682,44 @@ Opt4 = float | None
1682
1682
1683
1683
A = Type[int] | str
1684
1684
B: TypeAlias = Type[int] | str
1685
+ C = type[int] | str
1686
+
1687
+ D = type[int] | str
1688
+ x: D
1689
+ reveal_type(x)
1690
+ E: TypeAlias = type[int] | str
1691
+ y: E
1692
+ reveal_type(y)
1693
+ F = list[type[int] | str]
1694
+
1695
+ T = TypeVar("T", int, str)
1696
+ def foo(x: T) -> T:
1697
+ A = type[int] | str
1698
+ a: A
1699
+ return x
1685
1700
[out]
1686
1701
_testTypeAliasWithNewStyleUnion.py:5: note: Revealed type is "typing._SpecialForm"
1702
+ _testTypeAliasWithNewStyleUnion.py:25: note: Revealed type is "Union[Type[builtins.int], builtins.str]"
1703
+ _testTypeAliasWithNewStyleUnion.py:28: note: Revealed type is "Union[Type[builtins.int], builtins.str]"
1687
1704
1688
1705
[case testTypeAliasWithNewStyleUnionInStub]
1689
1706
# flags: --python-version 3.7
1690
1707
import m
1708
+ a: m.A
1709
+ reveal_type(a)
1710
+ b: m.B
1711
+ reveal_type(b)
1712
+ c: m.C
1713
+ reveal_type(c)
1714
+ d: m.D
1715
+ reveal_type(d)
1716
+ e: m.E
1717
+ reveal_type(e)
1718
+ f: m.F
1719
+ reveal_type(f)
1691
1720
1692
1721
[file m.pyi]
1693
- from typing import Type
1722
+ from typing import Type, Callable
1694
1723
from typing_extensions import Literal, TypeAlias
1695
1724
1696
1725
Foo = Literal[1, 2]
@@ -1710,8 +1739,27 @@ Opt4 = float | None
1710
1739
1711
1740
A = Type[int] | str
1712
1741
B: TypeAlias = Type[int] | str
1742
+ C = type[int] | str
1743
+ reveal_type(C)
1744
+ D: TypeAlias = type[int] | str
1745
+ E = str | type[int]
1746
+ F: TypeAlias = str | type[int]
1747
+ G = list[type[int] | str]
1748
+ H = list[str | type[int]]
1749
+
1750
+ CU1 = int | Callable[[], str | bool]
1751
+ CU2: TypeAlias = int | Callable[[], str | bool]
1752
+ CU3 = int | Callable[[str | bool], str]
1753
+ CU4: TypeAlias = int | Callable[[str | bool], str]
1713
1754
[out]
1714
1755
m.pyi:5: note: Revealed type is "typing._SpecialForm"
1756
+ m.pyi:22: note: Revealed type is "typing._SpecialForm"
1757
+ _testTypeAliasWithNewStyleUnionInStub.py:4: note: Revealed type is "Union[Type[builtins.int], builtins.str]"
1758
+ _testTypeAliasWithNewStyleUnionInStub.py:6: note: Revealed type is "Union[Type[builtins.int], builtins.str]"
1759
+ _testTypeAliasWithNewStyleUnionInStub.py:8: note: Revealed type is "Union[Type[builtins.int], builtins.str]"
1760
+ _testTypeAliasWithNewStyleUnionInStub.py:10: note: Revealed type is "Union[Type[builtins.int], builtins.str]"
1761
+ _testTypeAliasWithNewStyleUnionInStub.py:12: note: Revealed type is "Union[builtins.str, Type[builtins.int]]"
1762
+ _testTypeAliasWithNewStyleUnionInStub.py:14: note: Revealed type is "Union[builtins.str, Type[builtins.int]]"
1715
1763
1716
1764
[case testEnumNameWorkCorrectlyOn311]
1717
1765
# flags: --python-version 3.11
@@ -1736,6 +1784,23 @@ _testEnumNameWorkCorrectlyOn311.py:13: note: Revealed type is "Literal['X']?"
1736
1784
_testEnumNameWorkCorrectlyOn311.py:14: note: Revealed type is "builtins.int"
1737
1785
_testEnumNameWorkCorrectlyOn311.py:15: note: Revealed type is "builtins.int"
1738
1786
1787
+ [case testTypeAliasNotSupportedWithNewStyleUnion]
1788
+ # flags: --python-version 3.9
1789
+ from typing_extensions import TypeAlias
1790
+ A = type[int] | str
1791
+ B = str | type[int]
1792
+ C = str | int
1793
+ D: TypeAlias = str | int
1794
+ [out]
1795
+ _testTypeAliasNotSupportedWithNewStyleUnion.py:3: error: Invalid type alias: expression is not a valid type
1796
+ _testTypeAliasNotSupportedWithNewStyleUnion.py:3: error: Value of type "Type[type]" is not indexable
1797
+ _testTypeAliasNotSupportedWithNewStyleUnion.py:4: error: Invalid type alias: expression is not a valid type
1798
+ _testTypeAliasNotSupportedWithNewStyleUnion.py:4: error: Value of type "Type[type]" is not indexable
1799
+ _testTypeAliasNotSupportedWithNewStyleUnion.py:5: error: Invalid type alias: expression is not a valid type
1800
+ _testTypeAliasNotSupportedWithNewStyleUnion.py:5: error: Unsupported left operand type for | ("Type[str]")
1801
+ _testTypeAliasNotSupportedWithNewStyleUnion.py:6: error: Invalid type alias: expression is not a valid type
1802
+ _testTypeAliasNotSupportedWithNewStyleUnion.py:6: error: Unsupported left operand type for | ("Type[str]")
1803
+
1739
1804
[case testTypedDictUnionGetFull]
1740
1805
from typing import Dict
1741
1806
from typing_extensions import TypedDict
0 commit comments