@@ -611,6 +611,18 @@ def test_method_descriptor_types(self):
611611 self .assertIsInstance (int .from_bytes , types .BuiltinMethodType )
612612 self .assertIsInstance (int .__new__ , types .BuiltinMethodType )
613613
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+
614626 def test_or_types_operator (self ):
615627 self .assertEqual (int | str , typing .Union [int , str ])
616628 self .assertNotEqual (int | list , typing .Union [int , str ])
@@ -657,18 +669,23 @@ def test_or_types_operator(self):
657669 with self .assertRaises (TypeError ):
658670 Example () | int
659671 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
661675 with self .assertRaises (TypeError ):
662- ( int | str ) < typing . Union [ str , int ]
676+ x < x
663677 with self .assertRaises (TypeError ):
664- (int | str ) < (int | bool )
678+ x <= x
679+ y = typing .Union [str , int ]
665680 with self .assertRaises (TypeError ):
666- (int | str ) <= (int | str )
681+ x < y
682+ y = int | bool
667683 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 )
672689
673690 def test_hash (self ):
674691 self .assertEqual (hash (int | str ), hash (str | int ))
@@ -873,15 +890,6 @@ def test_or_type_operator_reference_cycle(self):
873890 self .assertLessEqual (sys .gettotalrefcount () - before , leeway ,
874891 msg = 'Check for union reference leak.' )
875892
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-
885893
886894class MappingProxyTests (unittest .TestCase ):
887895 mappingproxy = types .MappingProxyType
0 commit comments