You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
isatty utility does not handle streams with detached buffers correctly with Python 3.14.9 and 3.15.1 #5825
We have this utility function for checking is a stream console output or not:
defisatty(stream):
# first check if buffer was detachedifhasattr(stream, "buffer") andstream.bufferisNone:
returnFalseifnothasattr(stream, "isatty"):
returnFalsetry:
returnstream.isatty()
exceptValueError: # Occurs if file is closed.returnFalse
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
Fix `isatty` utility with detached buffers