Skip to content

Support size limits in buffered-file readline - #2315

Open
Ra1nhy wants to merge 1 commit into
fsspec:masterfrom
Ra1nhy:codex/buffered-readline-size
Open

Ra1nhy wants to merge 1 commit into
fsspec:masterfrom
Ra1nhy:codex/buffered-readline-size

Conversation

@Ra1nhy

@Ra1nhy Ra1nhy commented Oct 17, 2026

Copy link
Copy Markdown

Summary

Support the optional size argument on AbstractBufferedFile.readline, following the IOBase contract.

The current signature rejects every positional size with TypeError. This also breaks an existing standard-library consumer: http.client.parse_headers() calls fp.readline(_MAXLINE + 1). A regression test exercises that parser against an AbstractBufferedFile backed by MemoryFileSystem, without network access.

Positive sizes now bound the returned bytes, stopping at a newline or EOF and preserving any unread bytes after the newline. No-argument, negative and None calls keep the existing readuntil path. Zero-sized calls retain the existing closed-file checks. Invalid non-integer sizes are rejected before consuming data.

Tests compare returned bytes and file positions with io.BytesIO across three cache types, empty content, line boundaries, repeated calls and seeking. A changelog entry is included. This does not change readlines(hint) or backend-specific overrides.

Validation

CPython 3.12.14, macOS, against upstream 685f62e:

  • New regression/control cases on unchanged production: 79 failed, 5 passed. With the fix: 84 passed.
  • Complete test_spec.py: 466 passed, 66 skipped, 1 xfailed (original baseline: 382 passed, 66 skipped, 1 xfailed).
  • Specification, core, caches, memory and local modules together: 1,097 passed, 91 skipped, 1 xfailed; one existing fork-related deprecation warning.
  • Ruff 0.14.3 check and format check passed for both Python files.
  • Strict Sphinx build was attempted but failed on an unchanged changelog inline-literal warning. A separate untouched upstream export reproduced the same warning at line 15 (line 18 with this entry).

Full optional/cloud/Docker/downstream tests and other Python/OS environments were not run. This is a reproducible API compatibility fix, not a claim of a production incident or measured performance improvement.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant