Skip to content

Accept integer-like FileIO and buffered seek positions - #16511

Closed
xiehuanyi wants to merge 2 commits into
python:mainfrom
xiehuanyi:fix/io-binary-seek-index-20261012
Closed

xiehuanyi wants to merge 2 commits into
python:mainfrom
xiehuanyi:fix/io-binary-seek-index-20261012

Conversation

@xiehuanyi

@xiehuanyi xiehuanyi commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

FileIO, BufferedReader, BufferedWriter, and BufferedRandom accept integer-like seek positions, including numpy.int64, but their stubs currently require int. Valid offset arguments therefore produce type errors.

Use SupportsIndex for these four seek position parameters. Regression checks retain the integer return type and rejection of string offsets. The BytesIO annotation stays compatible with existing subclasses that declare an integer-only offset, with a regression check for that shape.

Validation: focused strict mypy and Pyright pass. Official scoped mypy checks pass for Python 3.10–3.15, _io and io pass stubtest on Python 3.12.13, and all applicable pre-commit hooks pass. Runtime checks cover custom index objects and NumPy integer offsets, including the pure Python buffered implementations.

Developed, reviewed, and tested with AI assistance (Codex).

Copilot AI balanced review requested due to automatic review settings October 12, 2026 09:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

This comment has been minimized.

@xiehuanyi xiehuanyi changed the title Accept integer-like binary file seek positions Accept integer-like FileIO and buffered seek positions Oct 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't include the tests. Typeshed tests are never run, only tested against type checkers, so these tests only check that the type checkers work as expected.

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.

3 participants