Repository navigation
gh-159446: Avoid TypeError on FileIO construction - #159480
Merged
Merged
Conversation
FileIO can be constructed off a string or an integer file descriptor. It used PyLong_AsInt first to check "is this an integer". That raised a TypeError when passed a string which would then be silenced. Proactively check if it is a number with _PyIndex_Check saving instructions in the common filename path. Callgrind, instructions per `FileIO(path).readall()` + `close()` of a 111-byte file: | Build | base | this change | |------------------|-------:|------------:| | PGO+LTO | 10,641 | 8,918 | | -O3, no PGO | 14,154 | 12,016 | pyperf, the same on a 182-byte file, PGO+LTO, 4 interleaved rounds of 10 processes: | Benchmark | base | this change | |----------------|:-------:|:---------------------:| | fileio_readall | 3.71 us | 3.62 us: 1.02x faster | Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cmaloney
force-pushed
the
fileiospeed_1_typeerror
branch
from
October 15, 2026 18:03
7305371 to
83216f0
Compare
Contributor
Author
|
apologies for the force push |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FileIO can be constructed off a string or an integer file descriptor. It used PyLong_AsInt first to check "is this a integer". That raised a TypeError when passed a string which would then be silenced. Proactively check if it is a number with _PyIndex_Check saving instructions in the common filename path.
Callgrind, instructions per
FileIO(path).readall()+close()of a 111-byte file:pyperf, the same on a 182-byte file, PGO+LTO, 4 interleaved rounds of 10 processes: