Skip to content

isatty utility does not handle streams with detached buffers correctly with Python 3.14.9 and 3.15.1 #5825

Closed

Description

@pekkaklarck

We have this utility function for checking is a stream console output or not:

def isatty(stream):
    # first check if buffer was detached
    if hasattr(stream, "buffer") and stream.buffer is None:
        return False
    if not hasattr(stream, "isatty"):
        return False
    try:
        return stream.isatty()
    except ValueError:  # Occurs if file is closed.
        return False

The check for detached buffers was added by PR #1948 that fixes issue #2003. A unit test for the fix fails on the hasattr(stream, "buffer") line with a ValueError when using the recently released Python 3.14.9 and 3.15.1. Earlier versions, including 3.14.8 and 3.15.0, work fine.

I consider hasattr failing like this a bug and will report that to Python itself, but we need to fix this in our code base as well. Good news is that fixing this requires only removing the separate detached buffer check. Calling stream.isatty() if the buffer is detached fails with a ValueError. The same error occurs also if the stream is closed and we already handle that,

Activity

  1. added this to the v7.5.1 milestone on Oct 23, 2026
  2. self-assigned this
    on Oct 23, 2026
  3. added theissue type on Oct 23, 2026
  4. added a commit that references this issue on Oct 23, 2026
    ca24954
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions