MCPcopy Index your code
hub / github.com/python/cpython / test_collections_protocols_allowed

Method test_collections_protocols_allowed

Lib/test/test_typing.py:4375–4404  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4373 self.assertIsInstance(c, C1)
4374
4375 def test_collections_protocols_allowed(self):
4376 @runtime_checkable
4377 class Custom(collections.abc.Iterable, Protocol):
4378 def close(self): ...
4379
4380 class A: pass
4381 class B:
4382 def __iter__(self):
4383 return []
4384 def close(self):
4385 return 0
4386
4387 self.assertIsSubclass(B, Custom)
4388 self.assertNotIsSubclass(A, Custom)
4389
4390 @runtime_checkable
4391 class ReleasableBuffer(collections.abc.Buffer, Protocol):
4392 def __release_buffer__(self, mv: memoryview) -> None: ...
4393
4394 class C: pass
4395 class D:
4396 def __buffer__(self, flags: int) -> memoryview:
4397 return memoryview(b'')
4398 def __release_buffer__(self, mv: memoryview) -> None:
4399 pass
4400
4401 self.assertIsSubclass(D, ReleasableBuffer)
4402 self.assertIsInstance(D(), ReleasableBuffer)
4403 self.assertNotIsSubclass(C, ReleasableBuffer)
4404 self.assertNotIsInstance(C(), ReleasableBuffer)
4405
4406 def test_io_reader_protocol_allowed(self):
4407 @runtime_checkable

Callers

nothing calls this directly

Calls 6

assertIsSubclassMethod · 0.80
assertNotIsSubclassMethod · 0.80
assertIsInstanceMethod · 0.80
assertNotIsInstanceMethod · 0.80
DClass · 0.70
CClass · 0.70

Tested by

no test coverage detected