@@ -45,6 +45,10 @@ def assertNotIsSubclass(self, cls, class_or_tuple, msg=None):
4545 message += ' : %s' % msg
4646 raise self .failureException (message )
4747
48+ def clear_caches (self ):
49+ for f in typing ._cleanups :
50+ f ()
51+
4852
4953class Employee :
5054 pass
@@ -509,6 +513,13 @@ def test_reversible(self):
509513 def test_protocol_instance_type_error (self ):
510514 with self .assertRaises (TypeError ):
511515 isinstance (0 , typing .SupportsAbs )
516+ class C1 (typing .SupportsInt ):
517+ def __int__ (self ) -> int :
518+ return 42
519+ class C2 (C1 ):
520+ pass
521+ c = C2 ()
522+ self .assertIsInstance (c , C1 )
512523
513524
514525class GenericTests (BaseTestCase ):
@@ -748,8 +759,12 @@ def foobar(x: List[List['CC']]): ...
748759 class CC : ...
749760 self .assertEqual (get_type_hints (foobar , globals (), locals ()), {'x' : List [List [CC ]]})
750761 T = TypeVar ('T' )
751- def barfoo (x : Tuple [T , ...]): ...
752- self .assertIs (get_type_hints (barfoo , globals (), locals ())['x' ], Tuple [T , ...])
762+ AT = Tuple [T , ...]
763+ def barfoo (x : AT ): ...
764+ self .assertIs (get_type_hints (barfoo , globals (), locals ())['x' ], AT )
765+ CT = Callable [..., List [T ]]
766+ def barfoo2 (x : CT ): ...
767+ self .assertIs (get_type_hints (barfoo2 , globals (), locals ())['x' ], CT )
753768
754769 def test_extended_generic_rules_subclassing (self ):
755770 class T1 (Tuple [T , KT ]): ...
@@ -800,6 +815,8 @@ def test_fail_with_bare_generic(self):
800815
801816 def test_type_erasure_special (self ):
802817 T = TypeVar ('T' )
818+ # this is the only test that checks type caching
819+ self .clear_caches ()
803820 class MyTup (Tuple [T , T ]): ...
804821 self .assertIs (MyTup [int ]().__class__ , MyTup )
805822 self .assertIs (MyTup [int ]().__orig_class__ , MyTup [int ])
0 commit comments