Visitar URL original
`_pyio.TextIOBase.readline` is missing a `size` arg · Issue #151596 · python/cpython · GitHub
Skip to content

_pyio.TextIOBase.readline is missing a size arg #151596

Closed

Description

@ShaharNaveh

Bug report

Bug description:

IOBase:

def readline(self, size=-1):

TextIOBase:

def readline(self):


This pattern seems to be missing only for readline AFAICT.
for truncate (which is also "unsupported" for TextIOBase) it's preserved:

IOBase:

def truncate(self, pos=None):

TextIOBase:

def truncate(self, pos=None):

(the same for write and others).

My proposed fix should be adding a size argument to readline with a default value of -1

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. picnixz commented on Jun 17, 2026

    @picnixz
    Member
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    pendingThe issue will be closed if no feedback is provided
    on Jun 17, 2026
  3. cmaloney commented on Jun 17, 2026

    @cmaloney
    Contributor

    truncate is a bit different as "The current stream position isn’t changed" (https://docs.python.org/3/library/io.html#io.IOBase.truncate).

    In the C implementation _io.TextIOWrapper, _io.BufferedIO, and _io.BytesIO do take an optional size argument today so this works as specified today. _pyio takes one in _pyio.TextIOWrapper.readline. _pyio isn't used in production anywhere as far as I'm aware and it's only the _pyio.TextIOBase.readline which is an abstract method missing the size=. I'm open to a tiny patch without NEWS adding size to _pyio.TextIOBase.readline it but I am doubtful that is worth the time / effort to write, review, and ship as _pyio is a CPython internal module.

  4. changed the title [-]`_pyio.TextIOBase.read` is missing a `size` arg[/-] [+]`_pyio.TextIOBase.readline` is missing a `size` arg[/+] on Jun 18, 2026
  5. ZeroIntensity commented on Jun 19, 2026

    @ZeroIntensity
    Member

    I'm open to a tiny patch without NEWS adding size to _pyio.TextIOBase.readline it but I am doubtful that is worth the time / effort to write, review, and ship as _pyio is a CPython internal module.

    I don't understand this. _pyio is a fallback when the C version of io isn't available, isn't it? Why is it considered internal?

  6. cmaloney commented on Jun 19, 2026

    @cmaloney
    Contributor

    As currently coded it's not used as a fallback and requires _io / the C version to build/run.

  7. ZeroIntensity commented on Jun 20, 2026

    @ZeroIntensity
    Member

    I suspect that other implementations might be using it anyway. _io can be written in an implementation's native language to get the primitive aspects, and then use _pyio from there to get the rest of the module.

    That said, this is a bit of a gray area. Do you know of any precedent to point to here?

  8. cmaloney commented on Jun 20, 2026

    @cmaloney
    Contributor

    I looked at some of the other Python implementations (ex. PyPy) that have been brought up and all I have investigated either use _io or have a fully independent implementation of the io API. Have had some in person conversations around what makes sense for _pyio long term. All that said a NEWS file is not going to cause harm here; I thought it would lead to more review round trips and wasn't really valuable hence trying to just leave out for the one line patch.

  9. ZeroIntensity commented on Jun 20, 2026

    @ZeroIntensity
    Member

    Yeah, no worries, I'm just being pedantic :)

  10. removed
    pendingThe issue will be closed if no feedback is provided
    on Jun 21, 2026
  11. added a commit that references this issue on Jun 21, 2026
  12. ZeroIntensity commented on Jun 22, 2026

    @ZeroIntensity
    Member

    Any strong opinions on whether we backport this to 3.13 and 3.14?

  13. vstinner commented on Jun 22, 2026

    @vstinner
    Member

    Oh. I read again the issue: the io module already has the size parameter in readline(). This change is only for the Python implementation which is not used by default.

    So I changed my mind and I'm fine with backporting the change to stable versions.

  14. added 3 commits that reference this issue on Jun 23, 2026
  15. added a commit that references this issue on Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard 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