Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.14] gh-146056: Fix repr() for lists and tuples containing NULLs (GH-146129)#146155

Merged
serhiy-storchaka merged 4 commits intopython:3.14from
serhiy-storchaka:backport-0f2246b-3.14
Mar 22, 2026
Merged

[3.14] gh-146056: Fix repr() for lists and tuples containing NULLs (GH-146129)#146155
serhiy-storchaka merged 4 commits intopython:3.14from
serhiy-storchaka:backport-0f2246b-3.14

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedMar 19, 2026
edited by github-actionsbot
Loading

pythonGH-146129)(cherry picked from commit0f2246b)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Victor Stinner <vstinner@python.org>

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

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

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.

Copy link
MemberAuthor

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 usesPyUnicodeWriter_WriteRepr(). And what about the user code? We leave it with a mine which explodes in rare and most likely not tested case.

Copy link
Member

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, onlytuple_repr() can callPyUnicodeWriter_WriteRepr() withNULL. For example,list_repr() cannot passNULL, becauseitem = Py_NewRef(v->ob_item[i]) crash if the item isNULL.

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 withPyUnicodeWriter_WriteRepr() which acceptsNULL, you can get crashes if an user uses Python 3.14.0 which doesn't acceptNULL. I don't think that it's a good idea to change the API in a 3.14.x bugfix release.

Copy link
MemberAuthor

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 callrepr() 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 thatPyUnicodeWriter_WriteRepr() callsPyObject_Repr() onobj and writes the output intowriter.PyObject_Repr() works with NULL.

Copy link
Member

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 aversionchanged markup to document that the API changed.

Copy link
MemberAuthor

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.

Copy link
Member

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 aversionchanged markup in the 3.14 change to say that the API changed in Python 3.14.x.

Copy link
MemberAuthor

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.

@serhiy-storchakaserhiy-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
Copy link
Member

@vstinnervstinner left a 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 inPyUnicodeWriter_WriteRepr(). At least, the API change is now documented.

@serhiy-storchaka
Copy link
MemberAuthor

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

@serhiy-storchakaserhiy-storchaka merged commit7965133 intopython:3.14Mar 22, 2026
51 checks passed
@miss-islington-app
Copy link

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

@serhiy-storchakaserhiy-storchaka deleted the backport-0f2246b-3.14 branchMarch 22, 2026 07:25
@miss-islington-app
Copy link

Sorry,@serhiy-storchaka, I could not cleanly backport this to3.13 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker 796513306fdc1184452ea644b485f83511f39528 3.13

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull requestMar 22, 2026
…LLs (pythonGH-146129) (pythonGH-146155)(cherry picked from commit0f2246b)(cherry picked from commit7965133)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Victor Stinner <vstinner@python.org>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull requestMar 22, 2026
…GH-146129) (pythonGH-146155)(cherry picked from commit0f2246b)(cherry picked from commit7965133)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app
Copy link

GH-146271 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelMar 22, 2026
serhiy-storchaka added a commit that referenced this pull requestMar 22, 2026
…H-146155) (GH-146271)(cherry picked from commit0f2246b)(cherry picked from commit7965133)Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@vstinnervstinnervstinner approved these changes

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@serhiy-storchaka@vstinner

[8]ページ先頭

©2009-2026 Movatter.jp