Skip to content

gh-162525: Fix json C encoder for str subclass separators - #162526

Merged
vstinner merged 6 commits into
python:mainfrom
thejesh23:fix-json-str-subclass-separators
Nov 27, 2026
Merged

vstinner merged 6 commits into
python:mainfrom
thejesh23:fix-json-str-subclass-separators

Conversation

@thejesh23

@thejesh23 thejesh23 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Write the separators with _PyUnicodeWriter_WriteStr(), like gh-148241 did for keys and values.

The new tests fail for C without the fix. test_json passes, also with -R 3:3.

Comment thread Lib/test/test_json/test_separators.py Outdated
return "StrSubclass"

h = {'a': [1, 2], 'b': 3}
seps = (StrSubclass(','), StrSubclass(':'))

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.

Can you use separators different than default seperators, to check that they are used?

For example, use (',_', ':_') or (', ', ': ') (1 and 2 spaces).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, switched to (',_', ':_').

@thejesh23
thejesh23 requested a review from vstinner November 27, 2026 01:15
@vstinner vstinner added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 27, 2026

@vstinner vstinner 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

@vstinner
vstinner merged commit 551df9d into python:main Nov 27, 2026
68 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @thejesh23 for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @thejesh23 and @vstinner, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 551df9d7d6054dac9ce78a2f04d46113b1ef9650 3.14

@bedevere-app

bedevere-app Bot commented Nov 27, 2026

Copy link
Copy Markdown

GH-162744 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 27, 2026
@bedevere-app

bedevere-app Bot commented Nov 27, 2026

Copy link
Copy Markdown

GH-162746 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 27, 2026
@vstinner

Copy link
Copy Markdown
Member

Merged. Thanks for the fix!

vstinner added a commit that referenced this pull request Nov 27, 2026
…2526) (#162746)

gh-162525: Fix json C encoder for str subclass separators (#162526)

(cherry picked from commit 551df9d)

Co-authored-by: Thejesh <thejesh36@gmail.com>
vstinner pushed a commit that referenced this pull request Nov 27, 2026
…162526) (#162744)

gh-162525: Fix json C encoder for str subclass separators (GH-162526)
(cherry picked from commit 551df9d)

Co-authored-by: Thejesh <thejesh36@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants