Uh oh!
There was an error while loading. Please reload this page.
gh-149046: fix: correctly handle str subclasses in StringIO - #149047
Conversation
9451278 to
47788ecCompare47788ec to
4f0649eCompareStringIOstr subclasses in StringIO
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM. 👍
@vstinner, should not we add PyUnicodeWriter_WriteRawStr()?
vstinner
commented
Jun 1, 2026
Oh, that's the same issue that gh-148241 which was fixed in the JSON, also using the private function: // gh-148241: Avoid PyUnicodeWriter_WriteStr() which calls str(obj)// on str subclassesif (_PyUnicodeWriter_WriteStr((_PyUnicodeWriter*)writer, pystr) <0) {
return-1;
}
Yes, we should add a new function since the issue was identified in at least two places of the Python stdlib. So there is a need for such API. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Thanks @KowalskiThomas for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15. |
GH-150706 is a backport of this pull request to the 3.15 branch. |
GH-150707 is a backport of this pull request to the 3.14 branch. |
vstinner
commented
Jun 1, 2026
Merged, thanks for the fix @KowalskiThomas. @serhiy-storchaka: I will work on adding |
serhiy-storchaka
commented
Jun 1, 2026
Go ahead! |
What is this PR?
This PR is, in a way, a follow-up from #148241.
This other PR fixed a breaking change in behaviour where classes inheriting
strwould have__str__called on them when instead of using the "underlying"stritself. The PR fixed the problem for JSON serialisation, but seemingly missed some other call sites, includingStringIO. This seems to affect Python 3.14+ (but works as expected on 3.13).This is a reproducer.
... gives
AssertionError: got 'WRONG_VALUE'StringIObreaking change forstrsubclasses #149046