Skip to content

_pyio.BytesIO.peek() returns bytearray instead of bytes #155389

Description

@fedonman

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.

importio, _pyioclassIdx:
def__index__(self):
return3formodin (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

No one assigned

    Labels

    3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-IOtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions