Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

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

Open
serhiy-storchaka wants to merge 3 commits intopython:3.14from
serhiy-storchaka:list-repr-null-3.14
Open

[3.14] gh-146056: Fix repr() for lists and tuples containing NULLs (GH-146129) (alt)#146204
serhiy-storchaka wants to merge 3 commits intopython:3.14from
serhiy-storchaka:list-repr-null-3.14

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Mar 20, 2026

(cherry picked from commit 0f2246b)

This is an alternative to #146155 which only fixes PyUnicodeWriter_WriteRepr() for internal use, leaving users with the broken variant.


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

pythonGH-146129)

(cherry picked from commit 0f2246b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@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 list.__repr__() for lists containing NULLs (GH-146129) (alt) Mar 20, 2026
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

I don't think that this hack is needed. I would prefer to only change tuple_repr() and list_repr().

@@ -0,0 +1 @@
:c:func:`PyUnicodeWriter_WriteRepr` now supports ``NULL`` argument.
Copy link
Member

Choose a reason for hiding this comment

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

This is no longer true.

PyObject *obj);
#if defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_MODULE)
#define PyUnicodeWriter_WriteRepr _PyUnicodeWriter_WriteReprTrue
#endif
Copy link
Member

Choose a reason for hiding this comment

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

It looks like a bad hack to me. I don't think that it's needed: only tuple_repr() and list_repr() should be modified to accept NULL: #146155 (comment), other functions cannot call PyUnicodeWriter_WriteRepr() with NULL.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to minimize the diff. If you prefer, we can simply replace PyUnicodeWriter_WriteRepr with _PyUnicodeWriter_WriteReprTrue. This will make future backports more difficult.

We cannot be sure that this is not needed until we analyze every use of PyUnicodeWriter_WriteRepr. This will take a time. Even if it is not needed right now, it can be needed after future backports.

@serhiy-storchaka serhiy-storchaka changed the title [3.14] gh-146056: Fix list.__repr__() for lists containing NULLs (GH-146129) (alt) [3.14] gh-146056: Fix repr() for lists and tuples containing NULLs (GH-146129) (alt) Mar 20, 2026
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.

2 participants