@@ -611,6 +611,18 @@ def test_method_descriptor_types(self):
611
611
self .assertIsInstance (int .from_bytes , types .BuiltinMethodType )
612
612
self .assertIsInstance (int .__new__ , types .BuiltinMethodType )
613
613
614
+ def test_ellipsis_type (self ):
615
+ self .assertIsInstance (Ellipsis , types .EllipsisType )
616
+
617
+ def test_notimplemented_type (self ):
618
+ self .assertIsInstance (NotImplemented , types .NotImplementedType )
619
+
620
+ def test_none_type (self ):
621
+ self .assertIsInstance (None , types .NoneType )
622
+
623
+
624
+ class UnionTests (unittest .TestCase ):
625
+
614
626
def test_or_types_operator (self ):
615
627
self .assertEqual (int | str , typing .Union [int , str ])
616
628
self .assertNotEqual (int | list , typing .Union [int , str ])
@@ -657,18 +669,23 @@ def test_or_types_operator(self):
657
669
with self .assertRaises (TypeError ):
658
670
Example () | int
659
671
x = int | str
660
- self .assertNotEqual (x , {})
672
+ self .assertEqual (x , int | str )
673
+ self .assertEqual (x , str | int )
674
+ self .assertNotEqual (x , {}) # should not raise exception
661
675
with self .assertRaises (TypeError ):
662
- ( int | str ) < typing . Union [ str , int ]
676
+ x < x
663
677
with self .assertRaises (TypeError ):
664
- (int | str ) < (int | bool )
678
+ x <= x
679
+ y = typing .Union [str , int ]
665
680
with self .assertRaises (TypeError ):
666
- (int | str ) <= (int | str )
681
+ x < y
682
+ y = int | bool
667
683
with self .assertRaises (TypeError ):
668
- # Check that we don't crash if typing.Union does not have a tuple in __args__
669
- x = typing .Union [str , int ]
670
- x .__args__ = [str , int ]
671
- (int | str ) == x
684
+ x < y
685
+ # Check that we don't crash if typing.Union does not have a tuple in __args__
686
+ y = typing .Union [str , int ]
687
+ y .__args__ = [str , int ]
688
+ self .assertEqual (x , y )
672
689
673
690
def test_hash (self ):
674
691
self .assertEqual (hash (int | str ), hash (str | int ))
@@ -873,15 +890,6 @@ def test_or_type_operator_reference_cycle(self):
873
890
self .assertLessEqual (sys .gettotalrefcount () - before , leeway ,
874
891
msg = 'Check for union reference leak.' )
875
892
876
- def test_ellipsis_type (self ):
877
- self .assertIsInstance (Ellipsis , types .EllipsisType )
878
-
879
- def test_notimplemented_type (self ):
880
- self .assertIsInstance (NotImplemented , types .NotImplementedType )
881
-
882
- def test_none_type (self ):
883
- self .assertIsInstance (None , types .NoneType )
884
-
885
893
886
894
class MappingProxyTests (unittest .TestCase ):
887
895
mappingproxy = types .MappingProxyType
0 commit comments