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

Class RawIOKeepsReference

Lib/test/test_io/test_general.py:615–625  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

613 # gh-60107: Ensure a "Raw I/O" which keeps a reference to the
614 # mutable memory doesn't allow making a mutable bytes.
615 class RawIOKeepsReference(self.MockRawIOWithoutRead):
616 def __init__(self, *args, **kwargs):
617 self.buf = None
618 super().__init__(*args, **kwargs)
619
620 def readinto(self, buf):
621 # buf is the bytearray so keeping a reference to it doesn't keep
622 # the memory alive; a memoryview does.
623 self.buf = memoryview(buf)
624 buf[0:4] = self._read_stack.pop()
625 return 3
626
627 with self.assertRaises(BufferError):
628 rawio = RawIOKeepsReference([b"1234"])

Callers 1

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…