mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-104555: Fix isinstance() and issubclass() for runtime-checkable protocols that use PEP 695 (#104556)
Fixes #104555
This commit is contained in:
parent
f40890b124
commit
1163782868
2 changed files with 19 additions and 1 deletions
|
@ -3134,6 +3134,24 @@ class ProtocolTests(BaseTestCase):
|
|||
|
||||
self.assertIsInstance(Test(), PSub)
|
||||
|
||||
def test_pep695_generic_protocol_callable_members(self):
|
||||
@runtime_checkable
|
||||
class Foo[T](Protocol):
|
||||
def meth(self, x: T) -> None: ...
|
||||
|
||||
class Bar[T]:
|
||||
def meth(self, x: T) -> None: ...
|
||||
|
||||
self.assertIsInstance(Bar(), Foo)
|
||||
self.assertIsSubclass(Bar, Foo)
|
||||
|
||||
@runtime_checkable
|
||||
class SupportsTrunc[T](Protocol):
|
||||
def __trunc__(self) -> T: ...
|
||||
|
||||
self.assertIsInstance(0.0, SupportsTrunc)
|
||||
self.assertIsSubclass(float, SupportsTrunc)
|
||||
|
||||
def test_init_called(self):
|
||||
T = TypeVar('T')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue