Skip to content

gh-163135: Return None from _pyio.TextIOWrapper.newlines without universal newlines - #163136

Closed
Chetansahney wants to merge 2 commits into
python:mainfrom
Chetansahney:gh-163135-pyio-newlines
Closed

Chetansahney wants to merge 2 commits into
python:mainfrom
Chetansahney:gh-163135-pyio-newlines

Conversation

@Chetansahney

@Chetansahney Chetansahney commented Dec 4, 2026 •

Copy link
Copy Markdown

_pyio.TextIOWrapper.newlines now returns None when the decoder has no newlines attribute, as the C implementation does, instead of raising AttributeError. Only universal newlines mode uses an IncrementalNewlineDecoder; with newline='\n', '\r' or '\r\n' (including _pyio.StringIO's default) the plain codec decoder has no such attribute.

Tests: test_newlines_input in test_textio.py now checks newlines for each mode, and test_newlines_property_without_universal_newlines in test_memoryio.py covers StringIO. Both fail for the Python implementation without the fix. test_io passes.

I found this with Claude Code while comparing the C and Python io implementations, and reviewed the fix and tests myself.

Return None, like the C implementation, instead of raising
AttributeError when newline is '\n', '\r' or '\r\n'.
@picnixz

picnixz commented Dec 4, 2026

Copy link
Copy Markdown
Member

_pyio is getting removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants