Title: `structseq_repr` mislabels unnamed `PyStructSequence` fields (e.g. `os.stat_result` slots 7–9) · Issue #154387 · python/cpython · GitHub
Open Graph Title: `structseq_repr` mislabels unnamed `PyStructSequence` fields (e.g. `os.stat_result` slots 7–9) · Issue #154387 · python/cpython
X Title: `structseq_repr` mislabels unnamed `PyStructSequence` fields (e.g. `os.stat_result` slots 7–9) · Issue #154387 · python/cpython
Description: Bug report Bug description: structseq_repr() indexes tp_members by visible sequence position, but tp_members is built with every PyStructSequence_UnnamedField entry skipped (packed). As a result, every visible slot at or after the first ...
Open Graph Description: Bug report Bug description: structseq_repr() indexes tp_members by visible sequence position, but tp_members is built with every PyStructSequence_UnnamedField entry skipped (packed). As a result, e...
X Description: Bug report Bug description: structseq_repr() indexes tp_members by visible sequence position, but tp_members is built with every PyStructSequence_UnnamedField entry skipped (packed). As a result, e...
Opengraph URL: https://github.com/python/cpython/issues/154387
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`structseq_repr` mislabels unnamed `PyStructSequence` fields (e.g. `os.stat_result` slots 7–9)","articleBody":"# Bug report\n\n### Bug description:\n\n`structseq_repr()` indexes `tp_members` by visible sequence position, but `tp_members` is built with every `PyStructSequence_UnnamedField` entry skipped (packed). As a result, every visible slot at or after the first unnamed field is labeled with the name of a later (hidden) field. For `os.stat_result`, the unnamed integer time slots 7–9 borrow the names of the hidden `st_atime`/`st_mtime`/`st_ctime` **float** fields.\n\n---\n\nReal-world case — a plain `os.stat()`. The repr prints `st_atime=\u003cinteger seconds>`, but the `st_atime` *attribute* is the float with sub-second precision — they are different fields:\n\n```python\n>>> import os\n>>> st = os.stat(os.curdir)\n>>> st\nos.stat_result(st_mode=16877, st_ino=1367263, st_dev=16777232, st_nlink=43,\n st_uid=501, st_gid=20, st_size=1376,\n st_atime=1784619363, st_mtime=1784619363, st_ctime=1784619363)\n>>> st[7] # sequence slot 7 — the integer atime\n1784619363\n>>> st.st_atime # the .st_atime attribute — a different, hidden float field\n1784619363.4590902\n```\n\nSynthetic case, isolating the mechanism with distinct values per field:\n\n```python\n>>> # The repr always labels sequence slot 7 \"st_atime\", printing slot 7's value:\n>>> st = os.stat_result(range(22))\n>>> st\nos.stat_result(st_mode=0, st_ino=1, st_dev=2, st_nlink=3, st_uid=4, st_gid=5,\n st_size=6, st_atime=7, st_mtime=8, st_ctime=9)\n>>> st[7]\n7\n\n>>> # But the .st_atime ATTRIBUTE is the hidden field at index 10:\n>>> st.st_atime # field 10 supplied -> 10\n10 # surprise! differs from the repr above\n\n>>> os.stat_result(range(11)).st_atime # field 10 supplied -> 10\n10\n>>> os.stat_result(range(10)).st_atime # field 10 NOT supplied -> falls back to slot 7 -> 7\n7 # surprise! # **UPDATE**: this is an intentional behavior in overrided `statresult_new`\n\n>>> os.stat_result.n_sequence_fields, os.stat_result.n_unnamed_fields\n(10, 3)\n>>> os.stat_result.__match_args__ # correctly excludes the 3 unnamed slots\n('st_mode', 'st_ino', 'st_dev', 'st_nlink', 'st_uid', 'st_gid', 'st_size')\n```\n\nThe mislabel is easy to miss: when only the 10 sequence fields are supplied (`range(10)`), the hidden float `st_atime` (index 10) is unset and derives from the integer slot 7, so the repr and the attribute coincidentally agree. Supplying field 10 (`range(11)` or more, or a real `os.stat()`) makes them disagree.\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154434\n* gh-154684\n* gh-154687\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/XuehaiPan","@type":"Person","name":"XuehaiPan"},"datePublished":"2026-07-21T16:28:02Z","url":"https://github.com/python/cpython/issues/154387"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8d9eecae-9330-088d-d6c3-3b92c65e3b7d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EB6E:3A73AA:356ACCB:43B0855:6B021B37 |
| html-safe-nonce | 4c9cd0cc95ab310ad431200f0e3377da66f189ee063cb375399745dbdef0c612 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjZFOjNBNzNBQTozNTZBQ0NCOjQzQjA4NTU6NkIwMjFCMzciLCJ2aXNpdG9yX2lkIjoiNzQ1MDI2NDE0MTMzMzQwNDQ3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b03b1b2a4d3959fdcae73054024b9515210199b7651955f9025c54280946d7fc |
| hovercard-subject-tag | issue:4940987476 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/154387/issue_layout |
| twitter:image | https://opengraph.githubassets.com/04a68b128070d37f88683e39739464b78691eff5b7fe3996b71908ec0df421bd/python/cpython/issues/154387 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/04a68b128070d37f88683e39739464b78691eff5b7fe3996b71908ec0df421bd/python/cpython/issues/154387 |
| og:image:alt | Bug report Bug description: structseq_repr() indexes tp_members by visible sequence position, but tp_members is built with every PyStructSequence_UnnamedField entry skipped (packed). As a result, e... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | XuehaiPan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width