FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-157710: Enable read-only optimization in PyUnicodeWriter by vstinner · Pull Request #157861 · python/cpython · GitHub

Repository navigation

gh-157710: Enable read-only optimization in PyUnicodeWriter - #157861

Merged
vstinner merged 6 commits into
python:mainfrom
vstinner:writer_readonly
Sep 21, 2026
Merged

vstinner merged 6 commits into
python:mainfrom
vstinner:writer_readonly

Conversation

vstinner commented Sep 20, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

If the first and only write to a PyUnicodeWriter is a Python str object, PyUnicodeWriter_Finish() returns the object unchanged.

Move test_unicode_equal() to the correct test case: CAPITest.

If the first and only write to a PyUnicodeWriter is a Python str
object, PyUnicodeWriter_Finish() returns the object unchanged.

Move test_unicode_equal() to the correct test case: CAPITest.
vstinner merged commit 21223c9 into python:main Sep 21, 2026
52 checks passed
vstinner deleted the writer_readonly branch September 21, 2026 08:32
vstinner pushed a commit that referenced this pull request Sep 28, 2026
…158214)

Since GH-157861, every writer uses the read-only optimization of
_PyUnicodeWriter_WriteStr(), so the first write of a str subclass
instance into an empty writer kept that object as the buffer, and
PyUnicodeWriter_Finish() returned it.  io.StringIO.getvalue() then
returned the written object itself, and the next write re-read it
through its __str__() method, which changed the contents and could make
read() read past the end of the buffer.

Only use the read-only optimization for exact str objects.  A subclass
is copied into a new buffer, as before GH-157861.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL