GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.14] gh-146056: Fix repr() for lists and tuples containing NULLs (GH-146129) by serhiy-storchaka · Pull Request #146155 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Mar 19, 2026 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

(cherry picked from commit 0f2246b)

  • Issue: Crash in repr() for lists containing NULLs #146056

📚 Documentation preview 📚: https://cpython-previews--146155.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka @vstinner
[3.14] pythongh-146056: Fix list.__repr__() for lists containing NULLs (
3af9bbb
pythonGH-146129)

(cherry picked from commit 0f2246b)

Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.13 only security fixes label Mar 19, 2026
This was referenced Mar 19, 2026
Crash in repr() for lists containing NULLs #146056
Closed
gh-146056: Fix repr() for lists and tuples containing NULLs #146129
Merged
@bedevere-app bedevere-app Bot added the awaiting core review label Mar 19, 2026
vstinner
vstinner reviewed Mar 19, 2026
View reviewed changes
Comment thread Doc/c-api/unicode.rst

Call :c:func:`PyObject_Repr` on *obj* and write the output into *writer*.

If *obj* is ``NULL``, write the string ``"<NULL>"`` into *writer*.

@vstinner vstinner Mar 19, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I would prefer to not change PyUnicodeWriter_WriteRepr() in a Python 3.14.x bugfix release. Can you leave it unchanged? Instead, modify list_repr() and tuple_repr() to write <NULL> string explicitly.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Mar 20, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We need to modify not only list_repr() and tuple_repr(), but all code that uses PyUnicodeWriter_WriteRepr(). And what about the user code? We leave it with a mine which explodes in rare and most likely not tested case.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Mar 20, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

In the Python code base, if I read the code correctly, only tuple_repr() can call PyUnicodeWriter_WriteRepr() with NULL. For example, list_repr() cannot pass NULL, because item = Py_NewRef(v->ob_item[i]) crash if the item is NULL.

And what about the user code? We leave it with a mine which explodes in rare and most likely not tested case.

My concern is that if you develop on (the future) Python 3.14.4 with PyUnicodeWriter_WriteRepr() which accepts NULL, you can get crashes if an user uses Python 3.14.0 which doesn't accept NULL. I don't think that it's a good idea to change the API in a 3.14.x bugfix release.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Mar 20, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Python 3.14.0 is broken. It crashes when you call repr() for uninitialized list or tuple, and it can crash in other cases. Does it mean that we should not backport the bugfix? I think that it is the nature of bugfix releases that they make the code which failed in earlier releases to pass.

The documentation says that PyUnicodeWriter_WriteRepr() calls PyObject_Repr() on obj and writes the output into writer. PyObject_Repr() works with NULL.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Mar 20, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If you insist to change PyUnicodeWriter_WriteRepr() API, please add a versionchanged markup to document that the API changed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Mar 20, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If we don't fix it in 3.14, we will need a versionchanged for 3.15. But we rarely add versionchanged for bugfixes, especially if the feature was added in the same version.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Mar 20, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'm suggesting to add a versionchanged markup in the 3.14 change to say that the API changed in Python 3.14.x.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Mar 20, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done. Created also a PR for adding in in main.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka serhiy-storchaka mentioned this pull request Mar 20, 2026
[3.14] gh-146056: Fix repr() for lists and tuples containing NULLs (GH-146129) (alt) #146204
Closed
serhiy-storchaka added 3 commits March 20, 2026 13:54
@serhiy-storchaka
Merge branch '3.14' into backport-0f2246b-3.14
b6751c1
@serhiy-storchaka
Add versionchanged.
c8b634e
@serhiy-storchaka
Update NEWS.
f36acab
@serhiy-storchaka serhiy-storchaka changed the title [3.14] gh-146056: Fix list.__repr__() for lists containing NULLs (GH-146129) [3.14] gh-146056: Fix repr() for lists and tuples containing NULLs (GH-146129) Mar 20, 2026
vstinner
vstinner approved these changes Mar 20, 2026
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM.

Ok, let's do that, accept NULL in PyUnicodeWriter_WriteRepr(). At least, the API change is now documented.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Mar 20, 2026
@vstinner vstinner mentioned this pull request Mar 20, 2026
Update docs for gh-146056 #146213
Merged
@serhiy-storchaka

serhiy-storchaka commented Mar 20, 2026

Copy link
Copy Markdown
Member Author

Note that no versionchanged was added for the API change in #146201 (I do not think that it is needed).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka
serhiy-storchaka merged commit 7965133 into python:3.14 Mar 22, 2026
51 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Mar 22, 2026
@miss-islington-app

miss-islington-app Bot commented Mar 22, 2026

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka
serhiy-storchaka deleted the backport-0f2246b-3.14 branch March 22, 2026 07:25
@miss-islington-app

miss-islington-app Bot commented Mar 22, 2026

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 796513306fdc1184452ea644b485f83511f39528 3.13
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app miss-islington-app Bot assigned serhiy-storchaka Mar 22, 2026
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Mar 22, 2026
@serhiy-storchaka @vstinner
[3.13] pythongh-146056: Fix repr() for lists and tuples containing NU…
94d687d
…LLs (pythonGH-146129) (pythonGH-146155)

(cherry picked from commit 0f2246b)
(cherry picked from commit 7965133)

Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Mar 22, 2026
@serhiy-storchaka @vstinner
[3.13] pythongh-146056: Fix repr() for lists containing NULLs (python…
bb5d229
…GH-146129) (pythonGH-146155)

(cherry picked from commit 0f2246b)
(cherry picked from commit 7965133)

Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
@bedevere-app

bedevere-app Bot commented Mar 22, 2026

Copy link
Copy Markdown

GH-146271 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Mar 22, 2026
serhiy-storchaka added a commit that referenced this pull request Mar 22, 2026
@serhiy-storchaka @vstinner
[3.13] gh-146056: Fix repr() for lists containing NULLs (GH-146129) (G…
fab8267
…H-146155) (GH-146271)

(cherry picked from commit 0f2246b)
(cherry picked from commit 7965133)

Co-authored-by: Victor Stinner <[email protected]>
@serhiy-storchaka serhiy-storchaka removed their assignment Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@serhiy-storchaka @vstinner
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.