Skip to content

gh-160185: Fix CJK StreamWriter.reset() not returning to ASCII - #160186

Open
gpshead wants to merge 1 commit into
python:mainfrom
gpshead:cjk-streamwriter-reset
Open

gpshead wants to merge 1 commit into
python:mainfrom
gpshead:cjk-streamwriter-reset

Conversation

@gpshead

@gpshead gpshead commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

MultibyteStreamWriter.reset() now passes an empty string to the encoder when nothing is pending instead of returning early, so the codec's reset hook writes the shift-back sequence again, as it did before gh-67436. It also drops the leaked stream.write() result.

Since reset() can now write bytes, StreamWriter.seek(), StreamReaderWriter.seek() and StreamRecoder.seek() reset the writer before moving the stream; otherwise seek(0) would write ESC ( B over offset 0. Other codecs' StreamWriter.reset() writes nothing, so the reorder doesn't change them.

Fixes #160185

ANT-2026-4AU4SRS4

reset() returned early when nothing was pending, so the shift-back
sequence of hz and iso2022_* was never written (regression from
pythongh-67436).  Also fix a reference leak of the stream.write() result.
@gpshead
gpshead force-pushed the cjk-streamwriter-reset branch from 345ec10 to d86d637 Compare October 22, 2026 04:44
@gpshead
gpshead marked this pull request as ready for review October 22, 2026 05:30
@gpshead
gpshead requested a review from corona10 as a code owner October 22, 2026 05:30
@gpshead gpshead added the sprint label Oct 22, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Sprint Oct 22, 2026

@corona10 corona10 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm!

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Sprint Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

CJK StreamWriter.reset() does not write the shift-back sequence

2 participants