@@ -1783,6 +1783,22 @@ def __init__(self):
17831783 self .assertIsInstance (Bar (), Foo )
17841784 self .assertNotIsInstance (object (), Foo )
17851785
1786+ @skipUnless (
1787+ hasattr (typing , "runtime_checkable" ),
1788+ "Test is only relevant if typing.runtime_checkable exists"
1789+ )
1790+ def test_typing_dot_runtimecheckable_on_Protocol (self ):
1791+ @typing .runtime_checkable
1792+ class Foo (Protocol ):
1793+ x : int
1794+
1795+ class Bar :
1796+ def __init__ (self ):
1797+ self .x = 42
1798+
1799+ self .assertIsInstance (Bar (), Foo )
1800+ self .assertNotIsInstance (object (), Foo )
1801+
17861802 def test_no_instantiation (self ):
17871803 class P (Protocol ): pass
17881804 with self .assertRaises (TypeError ):
@@ -4743,7 +4759,7 @@ def test_typing_extensions_defers_when_possible(self):
47434759 exclude |= {'final' , 'Any' , 'NewType' }
47444760 if sys .version_info < (3 , 12 ):
47454761 exclude |= {
4746- 'Protocol' , 'runtime_checkable' , ' SupportsAbs' , 'SupportsBytes' ,
4762+ 'Protocol' , 'SupportsAbs' , 'SupportsBytes' ,
47474763 'SupportsComplex' , 'SupportsFloat' , 'SupportsIndex' , 'SupportsInt' ,
47484764 'SupportsRound' , 'TypedDict' , 'is_typeddict' , 'NamedTuple' , 'Unpack' ,
47494765 }
0 commit comments