@@ -765,6 +765,20 @@ def read_write_attr(self, val): self._val = val
765
765
766
766
@collect_cases
767
767
def test_type_alias (self ) -> Iterator [Case ]:
768
+ yield Case (
769
+ stub = """
770
+ import collections.abc
771
+ import re
772
+ import typing
773
+ from typing import Callable, Dict, Generic, Iterable, List, Match, Tuple, TypeVar, Union
774
+ """ ,
775
+ runtime = """
776
+ import collections.abc
777
+ import re
778
+ from typing import Callable, Dict, Generic, Iterable, List, Match, Tuple, TypeVar, Union
779
+ """ ,
780
+ error = None ,
781
+ )
768
782
yield Case (
769
783
stub = """
770
784
class X:
@@ -778,27 +792,18 @@ class Y: ...
778
792
""" ,
779
793
error = "Y.f" ,
780
794
)
781
- yield Case (
782
- stub = """
783
- from typing import Tuple
784
- A = Tuple[int, str]
785
- """ ,
786
- runtime = "A = (int, str)" ,
787
- error = "A" ,
788
- )
795
+ yield Case (stub = "A = Tuple[int, str]" , runtime = "A = (int, str)" , error = "A" )
789
796
# Error if an alias isn't present at runtime...
790
797
yield Case (stub = "B = str" , runtime = "" , error = "B" )
791
798
# ... but only if the alias isn't private
792
799
yield Case (stub = "_C = int" , runtime = "" , error = None )
793
800
yield Case (
794
801
stub = """
795
- from typing import Tuple
796
802
D = tuple[str, str]
797
803
E = Tuple[int, int, int]
798
804
F = Tuple[str, int]
799
805
""" ,
800
806
runtime = """
801
- from typing import List, Tuple
802
807
D = Tuple[str, str]
803
808
E = Tuple[int, int, int]
804
809
F = List[str]
@@ -807,13 +812,11 @@ class Y: ...
807
812
)
808
813
yield Case (
809
814
stub = """
810
- from typing import Union
811
815
G = str | int
812
816
H = Union[str, bool]
813
817
I = str | int
814
818
""" ,
815
819
runtime = """
816
- from typing import Union
817
820
G = Union[str, int]
818
821
H = Union[str, bool]
819
822
I = str
@@ -822,16 +825,12 @@ class Y: ...
822
825
)
823
826
yield Case (
824
827
stub = """
825
- import typing
826
- from collections.abc import Iterable
827
- from typing import Dict
828
828
K = dict[str, str]
829
829
L = Dict[int, int]
830
- KK = Iterable[str]
830
+ KK = collections.abc. Iterable[str]
831
831
LL = typing.Iterable[str]
832
832
""" ,
833
833
runtime = """
834
- from typing import Iterable, Dict
835
834
K = Dict[str, str]
836
835
L = Dict[int, int]
837
836
KK = Iterable[str]
@@ -841,14 +840,12 @@ class Y: ...
841
840
)
842
841
yield Case (
843
842
stub = """
844
- from typing import Generic, TypeVar
845
843
_T = TypeVar("_T")
846
844
class _Spam(Generic[_T]):
847
845
def foo(self) -> None: ...
848
846
IntFood = _Spam[int]
849
847
""" ,
850
848
runtime = """
851
- from typing import Generic, TypeVar
852
849
_T = TypeVar("_T")
853
850
class _Bacon(Generic[_T]):
854
851
def foo(self, arg): pass
@@ -859,14 +856,11 @@ def foo(self, arg): pass
859
856
yield Case (stub = "StrList = list[str]" , runtime = "StrList = ['foo', 'bar']" , error = "StrList" )
860
857
yield Case (
861
858
stub = """
862
- import collections.abc
863
- from typing import Callable
864
- N = Callable[[str], bool]
859
+ N = typing.Callable[[str], bool]
865
860
O = collections.abc.Callable[[int], str]
866
- P = Callable[[str], bool]
861
+ P = typing. Callable[[str], bool]
867
862
""" ,
868
863
runtime = """
869
- from typing import Callable
870
864
N = Callable[[str], bool]
871
865
O = Callable[[int], str]
872
866
P = int
@@ -897,17 +891,7 @@ class Bar: pass
897
891
""" ,
898
892
error = None ,
899
893
)
900
- yield Case (
901
- stub = """
902
- from typing import Match
903
- M = Match[str]
904
- """ ,
905
- runtime = """
906
- from typing import Match
907
- M = Match[str]
908
- """ ,
909
- error = None ,
910
- )
894
+ yield Case (stub = "M = Match[str]" , runtime = "M = Match[str]" , error = None )
911
895
yield Case (
912
896
stub = """
913
897
class Baz:
@@ -940,37 +924,32 @@ def fizz(self): pass
940
924
if sys .version_info >= (3 , 10 ):
941
925
yield Case (
942
926
stub = """
943
- import collections.abc
944
- import re
945
- from typing import Callable, Dict, Match, Iterable, Tuple, Union
946
927
Q = Dict[str, str]
947
928
R = dict[int, int]
948
929
S = Tuple[int, int]
949
930
T = tuple[str, str]
950
931
U = int | str
951
932
V = Union[int, str]
952
- W = Callable[[str], bool]
933
+ W = typing. Callable[[str], bool]
953
934
Z = collections.abc.Callable[[str], bool]
954
- QQ = Iterable[str]
935
+ QQ = typing. Iterable[str]
955
936
RR = collections.abc.Iterable[str]
956
- MM = Match[str]
937
+ MM = typing. Match[str]
957
938
MMM = re.Match[str]
958
939
""" ,
959
940
runtime = """
960
- from collections.abc import Callable, Iterable
961
- from re import Match
962
941
Q = dict[str, str]
963
942
R = dict[int, int]
964
943
S = tuple[int, int]
965
944
T = tuple[str, str]
966
945
U = int | str
967
946
V = int | str
968
- W = Callable[[str], bool]
969
- Z = Callable[[str], bool]
970
- QQ = Iterable[str]
971
- RR = Iterable[str]
972
- MM = Match[str]
973
- MMM = Match[str]
947
+ W = collections.abc. Callable[[str], bool]
948
+ Z = collections.abc. Callable[[str], bool]
949
+ QQ = collections.abc. Iterable[str]
950
+ RR = collections.abc. Iterable[str]
951
+ MM = re. Match[str]
952
+ MMM = re. Match[str]
974
953
""" ,
975
954
error = None ,
976
955
)
0 commit comments