@@ -226,8 +226,8 @@ def test_type_function(self):
226
226
def test_int__format__ (self ):
227
227
def test (i , format_spec , result ):
228
228
# just make sure we have the unified type for integers
229
- assert type (i ) == int
230
- assert type (format_spec ) == str
229
+ self . assertIs ( type (i ), int )
230
+ self . assertIs ( type (format_spec ), str )
231
231
self .assertEqual (i .__format__ (format_spec ), result )
232
232
233
233
test (123456789 , 'd' , '123456789' )
@@ -782,8 +782,8 @@ def __subclasscheck__(cls, sub):
782
782
783
783
def test_or_type_operator_with_TypeVar (self ):
784
784
TV = typing .TypeVar ('T' )
785
- assert TV | str == typing .Union [TV , str ]
786
- assert str | TV == typing .Union [str , TV ]
785
+ self . assertEqual ( TV | str , typing .Union [TV , str ])
786
+ self . assertEqual ( str | TV , typing .Union [str , TV ])
787
787
self .assertIs ((int | TV )[int ], int )
788
788
self .assertIs ((TV | int )[int ], int )
789
789
@@ -887,43 +887,45 @@ def test_or_type_operator_with_forward(self):
887
887
ForwardBefore = 'Forward' | T
888
888
def forward_after (x : ForwardAfter [int ]) -> None : ...
889
889
def forward_before (x : ForwardBefore [int ]) -> None : ...
890
- assert typing .get_args (typing .get_type_hints (forward_after )['x' ]) == (int , Forward )
891
- assert typing .get_args (typing .get_type_hints (forward_before )['x' ]) == (int , Forward )
890
+ self .assertEqual (typing .get_args (typing .get_type_hints (forward_after )['x' ]),
891
+ (int , Forward ))
892
+ self .assertEqual (typing .get_args (typing .get_type_hints (forward_before )['x' ]),
893
+ (int , Forward ))
892
894
893
895
def test_or_type_operator_with_Protocol (self ):
894
896
class Proto (typing .Protocol ):
895
897
def meth (self ) -> int :
896
898
...
897
- assert Proto | str == typing .Union [Proto , str ]
899
+ self . assertEqual ( Proto | str , typing .Union [Proto , str ])
898
900
899
901
def test_or_type_operator_with_Alias (self ):
900
- assert list | str == typing .Union [list , str ]
901
- assert typing .List | str == typing .Union [typing .List , str ]
902
+ self . assertEqual ( list | str , typing .Union [list , str ])
903
+ self . assertEqual ( typing .List | str , typing .Union [typing .List , str ])
902
904
903
905
def test_or_type_operator_with_NamedTuple (self ):
904
- NT = namedtuple ('A' , ['B' , 'C' , 'D' ])
905
- assert NT | str == typing .Union [NT ,str ]
906
+ NT = namedtuple ('A' , ['B' , 'C' , 'D' ])
907
+ self . assertEqual ( NT | str , typing .Union [NT , str ])
906
908
907
909
def test_or_type_operator_with_TypedDict (self ):
908
910
class Point2D (typing .TypedDict ):
909
911
x : int
910
912
y : int
911
913
label : str
912
- assert Point2D | str == typing .Union [Point2D , str ]
914
+ self . assertEqual ( Point2D | str , typing .Union [Point2D , str ])
913
915
914
916
def test_or_type_operator_with_NewType (self ):
915
917
UserId = typing .NewType ('UserId' , int )
916
- assert UserId | str == typing .Union [UserId , str ]
918
+ self . assertEqual ( UserId | str , typing .Union [UserId , str ])
917
919
918
920
def test_or_type_operator_with_IO (self ):
919
- assert typing .IO | str == typing .Union [typing .IO , str ]
921
+ self . assertEqual ( typing .IO | str , typing .Union [typing .IO , str ])
920
922
921
923
def test_or_type_operator_with_SpecialForm (self ):
922
- assert typing .Any | str == typing .Union [typing .Any , str ]
923
- assert typing .NoReturn | str == typing .Union [typing .NoReturn , str ]
924
- assert typing .Optional [int ] | str == typing .Union [typing .Optional [int ], str ]
925
- assert typing .Optional [int ] | str == typing .Union [int , str , None ]
926
- assert typing .Union [int , bool ] | str == typing .Union [int , bool , str ]
924
+ self . assertEqual ( typing .Any | str , typing .Union [typing .Any , str ])
925
+ self . assertEqual ( typing .NoReturn | str , typing .Union [typing .NoReturn , str ])
926
+ self . assertEqual ( typing .Optional [int ] | str , typing .Union [typing .Optional [int ], str ])
927
+ self . assertEqual ( typing .Optional [int ] | str , typing .Union [int , str , None ])
928
+ self . assertEqual ( typing .Union [int , bool ] | str , typing .Union [int , bool , str ])
927
929
928
930
def test_or_type_operator_with_Literal (self ):
929
931
Literal = typing .Literal
@@ -955,12 +957,12 @@ class Ints(enum.IntEnum):
955
957
(Literal [1 ], Literal [Ints .B ]))
956
958
957
959
def test_or_type_repr (self ):
958
- assert repr (int | str ) == "int | str"
959
- assert repr ((int | str ) | list ) == "int | str | list"
960
- assert repr (int | (str | list )) == "int | str | list"
961
- assert repr (int | None ) == "int | None"
962
- assert repr (int | type (None )) == "int | None"
963
- assert repr (int | typing .GenericAlias (list , int )) == "int | list[int]"
960
+ self . assertEqual ( repr (int | str ), "int | str" )
961
+ self . assertEqual ( repr ((int | str ) | list ), "int | str | list" )
962
+ self . assertEqual ( repr (int | (str | list )), "int | str | list" )
963
+ self . assertEqual ( repr (int | None ), "int | None" )
964
+ self . assertEqual ( repr (int | type (None )), "int | None" )
965
+ self . assertEqual ( repr (int | typing .GenericAlias (list , int )), "int | list[int]" )
964
966
965
967
def test_or_type_operator_with_genericalias (self ):
966
968
a = list [int ]
0 commit comments