@@ -41,10 +41,10 @@ def clear_typing_caches():
4141class TypesTests (unittest .TestCase ):
4242
4343 def test_names (self ):
44- c_only_names = {'CapsuleType' , 'LazyImportType' ,
45- 'lookup_special_method' }
44+ c_only_names = {'CapsuleType' , 'LazyImportType' }
4645 ignored = {'new_class' , 'resolve_bases' , 'prepare_class' ,
47- 'get_original_bases' , 'DynamicClassAttribute' , 'coroutine' }
46+ 'get_original_bases' , 'DynamicClassAttribute' , 'coroutine' ,
47+ 'lookup_special_method' }
4848
4949 for name in c_types .__all__ :
5050 if name not in c_only_names | ignored :
@@ -727,7 +727,7 @@ def test_frame_locals_proxy_type(self):
727727 self .assertIsNotNone (frame )
728728 self .assertIsInstance (frame .f_locals , types .FrameLocalsProxyType )
729729
730- def test_lookup_special_method (self ):
730+ def _test_lookup_special_method (self , lookup ):
731731 class CM1 :
732732 def __enter__ (self ):
733733 return "__enter__ from class __dict__"
@@ -745,29 +745,36 @@ def __enter__(self):
745745 return "__enter__ from __slots__"
746746 self .__enter__ = __enter__
747747 cm1 = CM1 ()
748- meth = types . lookup_special_method (cm1 , "__enter__" )
748+ meth = lookup (cm1 , "__enter__" )
749749 self .assertIsNotNone (meth )
750750 self .assertEqual (meth (cm1 ), "__enter__ from class __dict__" )
751751
752- meth = types . lookup_special_method (cm1 , "__missing__" )
752+ meth = lookup (cm1 , "__missing__" )
753753 self .assertIsNone (meth )
754754
755755 with self .assertRaises (TypeError ):
756- types . lookup_special_method (cm1 , 123 )
756+ lookup (cm1 , 123 )
757757
758758 cm2 = CM2 ()
759- meth = types . lookup_special_method (cm2 , "__enter__" )
759+ meth = lookup (cm2 , "__enter__" )
760760 self .assertIsNone (meth )
761761
762762 cm3 = CM3 ()
763- meth = types . lookup_special_method (cm3 , "__enter__" )
763+ meth = lookup (cm3 , "__enter__" )
764764 self .assertIsNotNone (meth )
765765 self .assertEqual (meth (cm3 ), "__enter__ from __slots__" )
766766
767- meth = types . lookup_special_method ([], "__len__" )
767+ meth = lookup ([], "__len__" )
768768 self .assertIsNotNone (meth )
769769 self .assertEqual (meth ([]), 0 )
770770
771+ def test_lookup_special_method (self ):
772+ c_lookup = getattr (c_types , "lookup_special_method" )
773+ py_lookup = getattr (types , "lookup_special_method" )
774+ self ._test_lookup_special_method (c_lookup )
775+ self ._test_lookup_special_method (py_lookup )
776+
777+
771778class UnionTests (unittest .TestCase ):
772779
773780 def test_or_types_operator (self ):
0 commit comments