Closed
Labels
3.16new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug description:
_pyio.BytesIO.peek() returns a bytearray, while io.BytesIO.peek() returns bytes, which is what Doc/library/io.rst documents. It also rejects an __index__-able size that the C version accepts.
import io, _pyio
class Idx:
def __index__(self):
return 3
for mod in (io, _pyio):
b = mod.BytesIO(b'abcdef')
print(mod.__name__, 'peek() ->', type(b.peek()).__name__)
print(mod.__name__, 'peek(Idx()) ->', repr(b.peek(Idx())))io peek() -> bytes
io peek(Idx()) -> b'abc'
_pyio peek() -> bytearray
_pyio peek(Idx()) -> TypeError: '<' not supported between instances of 'Idx' and 'int'
BytesIO.peek() is new in 3.16 (GH-150917).
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
3.16new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
gh-155389: Return bytes from _pyio.BytesIO.peek() (GH-155390)