Repository navigation
python: propagate the real error for unseekable streams in identify_stream (#1473) - #1475
kaluli123123 wants to merge 8 commits into
Conversation
…tream `identify_stream()` bound `current_position` inside the `try` block but referenced it unconditionally in `finally`. For a readable-but-unseekable binary stream (e.g. `sys.stdin.buffer` on a pipe) `stream.tell()` raises, so the name was never bound and `finally` raised `UnboundLocalError`, demoting the actionable `OSError` to `__context__`. Hoist `tell()` out of the `try` block: there is nothing to restore until the position is known, and the only statement left inside `try` is the one that needs the restore. Fixes google#1473
Resolve the conflict in identify_stream() against the new stream-reading logic from main: keep main's block-based read, and keep this PR's fix of calling tell() before the try block so the real error of an unseekable stream is not masked by an UnboundLocalError.
|
Merged current Checks run locally in |
|
Thank you! I checked this against the current |
|
Updated the branch with current Local checks in |
…nseekable-position
|
Rebased-free update: merged the current
Validation run locally in
After the push, |
|
Synced with latest Local verification in
The fix and its regression test are unchanged by the merge. |
Fixes #1473.
Keep
tell()outside the restoringtry/finallyso unseekable streams retain their original error. Merged current main (8461733) and adapted the regression annotation toty; upstream block-based reads remain unchanged.Python 3.13: both stream regressions and the non-slow suite passed (42 passed, 1 skipped); lock, Ruff, formatting, ty, copyright, documentation, KB sync and real OS-pipe/CLI/module smokes passed.
Current-head workflows need maintainer authorization; formal approval is still required.