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
_pyio.TextIOWrapper.newlines raises AttributeError when newline translation is off #163135
In the pure-Python _pyio implementation, reading newlines from a TextIOWrapper or StringIO raises AttributeError after a read when newline is '\n', '\r' or '\r\n'. The C io module returns None. This includes _pyio.StringIO with its default newline='\n':
importio, _pyioformodin (io, _pyio):
s=mod.StringIO("a\n")
s.readline()
print(mod.__name__, s.newlines)
# io None# AttributeError: 'IncrementalDecoder' object has no attribute 'newlines'
Only universal newlines mode (newline=None or '') uses an IncrementalNewlineDecoder. The other modes use the plain codec decoder, which has no newlines attribute, but _pyio.TextIOWrapper.newlines reads it unconditionally. The C getter uses PyObject_GetOptionalAttr and returns None when the attribute is missing.
Activity
picnixz commentedon Dec 4, 2026
_pyio is getting removed
picnixz commentedon Dec 4, 2026
And fixing only on bugfix versions may need more changes so I do not think we will change it. cc @cmaloney
hugovk commentedon Dec 4, 2026
Link for reference: #163124