summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
diff options
context:
space:
mode:
authorAlex Waygood <Alex.Waygood@Gmail.com>2023-05-16 16:38:10 (GMT)
committerGitHub <noreply@github.com>2023-05-16 16:38:10 (GMT)
commit1163782868454287ca9ac170aaebca4beeb83192 (patch)
tree99dbc1179ab5ac328ae1b08c488e0625e065507a /Lib/test/test_typing.py
parentf40890b124a330b589c8093127be1274e15dbd7f (diff)
downloadcpython-1163782868454287ca9ac170aaebca4beeb83192.zip
cpython-1163782868454287ca9ac170aaebca4beeb83192.tar.gz
cpython-1163782868454287ca9ac170aaebca4beeb83192.tar.bz2
gh-104555: Fix isinstance() and issubclass() for runtime-checkable protocols that use PEP 695 (#104556)
Fixes #104555
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r--Lib/test/test_typing.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 71aff87..0cd67c5 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -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')