Skip to content
Closed
9 changes: 9 additions & 0 deletions Lib/test/test_structseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ def test_repr(self):
self.assertIn("st_ino=", rep)
self.assertIn("st_dev=", rep)

# Issue #154387: unnamed fields should not be mislabeled with named field names.

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.

This does not test the same things as the issue. Please be more thorough here.

st = os.stat_result(range(10))
rep = repr(st)
self.assertEqual(
rep,
"os.stat_result(st_mode=0, st_ino=1, st_dev=2, st_nlink=3, "
"st_uid=4, st_gid=5, st_size=6, 7, 8, 9)"

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.

I do not think extra items should actually ne considered if they are un-named, or at least they should be formatted differently. We jeed to discuss the format first because here, this repr would not work (you cannot just use it again as an input).

I do not know whether it is better to simply ignore unnamed fields or do something else.

)

def test_concat(self):
t1 = time.gmtime()
t2 = t1 + tuple(t1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :c:func:`structseq_repr` mislabeling unnamed :c:type:`PyStructSequence` fields. Patch by Pranav Choudhary.
27 changes: 15 additions & 12 deletions Objects/structseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,23 @@ structseq_repr(PyObject *op)
}

// Write name
const char *name_utf8 = typ->tp_members[i].name;
if (name_utf8 == NULL) {
PyErr_Format(PyExc_SystemError,
"In structseq_repr(), member %zd name is NULL"
" for type %.500s", i, typ->tp_name);
goto error;
}
if (PyUnicodeWriter_WriteUTF8(writer, name_utf8, -1) < 0) {
goto error;
const char *name_utf8 = NULL;
Py_ssize_t expected_offset = offsetof(PyStructSequence, ob_item) + i * sizeof(PyObject*);
for (Py_ssize_t k = 0; typ->tp_members[k].name != NULL; k++) {
if (typ->tp_members[k].offset == expected_offset) {
name_utf8 = typ->tp_members[k].name;
break;
}
}

// Write "=" + repr(value)
if (PyUnicodeWriter_WriteChar(writer, '=') < 0) {
goto error;
if (name_utf8 != NULL) {
if (PyUnicodeWriter_WriteUTF8(writer, name_utf8, -1) < 0) {
goto error;
}
// Write "="
if (PyUnicodeWriter_WriteChar(writer, '=') < 0) {
goto error;
}
}
PyObject *value = PyStructSequence_GetItem((PyObject*)obj, i);
assert(value != NULL);
Expand Down
14 changes: 2 additions & 12 deletions PCbuild/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ external dependencies. To build, simply run the "build.bat" script without
any arguments. After this succeeds, you can open the "pcbuild.sln"
solution in Visual Studio to continue development.

To build an installer package, refer to the README in the Tools/msi folder.
To build an installer package, refer to PC/layout.

The solution currently supports two platforms. The Win32 platform is
used to build standard x86-compatible 32-bit binaries, output into the
Expand Down Expand Up @@ -140,12 +140,6 @@ CPython in different ways:
pythonw
pythonw.exe, a variant of python.exe that doesn't open a Command
Prompt window
pylauncher
py.exe, the Python Launcher for Windows, see
https://docs.python.org/3/using/windows.html#launcher
pywlauncher
pyw.exe, a variant of py.exe that doesn't open a Command Prompt
window
_testembed
_testembed.exe, a small program that embeds Python for testing
purposes, used by test_capi.py
Expand All @@ -156,8 +150,6 @@ _freeze_module
_freeze_module.exe, used to regenerate frozen modules in Python
after changes have been made to the corresponding source files
(e.g. Lib\importlib\_bootstrap.py).
pyshellext
pyshellext.dll, the shell extension deployed with the launcher
python3dll
python3.dll, the PEP 384 Stable ABI dll
(not installed on free-threaded builds)
Expand Down Expand Up @@ -247,7 +239,7 @@ _sqlite3
https://www.sqlite.org/

_tkinter
Wraps version 9.0.3 of the Tk windowing system, which is downloaded
Wraps version 9.0.4 of the Tk windowing system, which is downloaded
from our binaries repository at
https://github.com/python/cpython-bin-deps.

Expand Down Expand Up @@ -420,8 +412,6 @@ _testclinic_limited extension, the file Modules/_testclinic_limited.c:
* Save and exit Visual Studio.
* Add `;_testclinic_limited` to `<TestModules Include="...">` in
PCbuild\pcbuild.proj.
* Update "exts" in Tools\msi\lib\lib_files.wxs file or in
Tools\msi\test\test_files.wxs file (for tests).
* PC\layout\main.py needs updating if you add a test-only extension whose name
doesn't start with "_test".
* Add the extension to PCbuild\readme.txt (this file).
Expand Down
Loading