summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-05-24 09:05:34 (GMT)
committerGitHub <noreply@github.com>2023-05-24 09:05:34 (GMT)
commitd10d1e3b10737a8426f92221e2788e40ad05b4e0 (patch)
tree66a9a80efe065d5ebdb34170a91a00b3c7804cec /Lib/test
parentb719dd8725a820a1af4b76c30ae87c23d8db68c0 (diff)
downloadcpython-d10d1e3b10737a8426f92221e2788e40ad05b4e0.zip
cpython-d10d1e3b10737a8426f92221e2788e40ad05b4e0.tar.gz
cpython-d10d1e3b10737a8426f92221e2788e40ad05b4e0.tar.bz2
[3.12] gh-104797: Allow Protocols to inherit from collections.abc.Buffer (GH-104827) (#104841)
gh-104797: Allow Protocols to inherit from collections.abc.Buffer (GH-104827) (cherry picked from commit c0ab7d401c736c37bf4462eef7c7d69fef8fab93) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_typing.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 9a3e642..a3fad6f 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -3546,6 +3546,22 @@ class ProtocolTests(BaseTestCase):
self.assertIsSubclass(B, Custom)
self.assertNotIsSubclass(A, Custom)
+ @runtime_checkable
+ class ReleasableBuffer(collections.abc.Buffer, Protocol):
+ def __release_buffer__(self, mv: memoryview) -> None: ...
+
+ class C: pass
+ class D:
+ def __buffer__(self, flags: int) -> memoryview:
+ return memoryview(b'')
+ def __release_buffer__(self, mv: memoryview) -> None:
+ pass
+
+ self.assertIsSubclass(D, ReleasableBuffer)
+ self.assertIsInstance(D(), ReleasableBuffer)
+ self.assertNotIsSubclass(C, ReleasableBuffer)
+ self.assertNotIsInstance(C(), ReleasableBuffer)
+
def test_builtin_protocol_allowlist(self):
with self.assertRaises(TypeError):
class CustomProtocol(TestCase, Protocol):