René's URL Explorer Experiment


Title: gh-154387: fix `structseq_repr` by labeling unnamed fields in repr as `` by XuehaiPan · Pull Request #154687 · python/cpython · GitHub

Open Graph Title: gh-154387: fix `structseq_repr` by labeling unnamed fields in repr as `` by XuehaiPan · Pull Request #154687 · python/cpython

X Title: gh-154387: fix `structseq_repr` by labeling unnamed fields in repr as `` by XuehaiPan · Pull Request #154687 · python/cpython

Description: Walk the members alongside the visible slots and label unnamed slots positionally as , which is correct regardless of where the unnamed fields sit among the visible ones. Before this PR, the member slots are accessed incorrectly in repr when there are unnamed fields. It can cause a spurious SystemError when the index reaches the number of named fields (n_fields - n_unnamed_fields), or display the unnamed fields with = using a later field's name. For example, a structseq type with WithUnnamed(first, , third, ) + [hidden .fifth], before this PR: >>> seq = WithUnnamed(range(5)) >>> repr(seq) Traceback (most recent call last): File "", line 1, in repr(seq) ~~~~^^^^^ SystemError: In structseq_repr(), member 3 name is NULL for type WithUnnamed # -> WithUnnamed(first=0, third=1, fifth=2, ) After this PR: >>> seq = WithUnnamed(range(5)) >>> seq WithUnnamed(first=0, =1, third=2, =3) >>> seq.fifth 4 Before this PR, for os.stat_result, the unnamed slots printed as the following field names st_atime/st_mtime/st_ctime. >>> st = os.stat_result(range(os.stat_result.n_fields)) >>> st os.stat_result(st_mode=0, st_ino=1, st_dev=2, st_nlink=3, st_uid=4, st_gid=5, st_size=6, st_atime=7, st_mtime=8, st_ctime=9) # borrow the following fields' names but use the unnamed fields' values >>> st[7] 7 >>> st.st_atime 10 >>> st = os.stat_result(tuple(range(10)) + (7.1, 8.2, 9.3)) >>> st os.stat_result(st_mode=0, st_ino=1, st_dev=2, st_nlink=3, st_uid=4, st_gid=5, st_size=6, st_atime=7, st_mtime=8, st_ctime=9) >>> st[7] # index = 7 is int 7 >>> st.st_atime # index = 10 is float 7.1 After this PR, a new custom statresult_repr is added analogously to statresult_new. The custom repr shows the fields 10-12 (always initialized in statresult_new) instead of generic (introduced in this PR). >>> st = os.stat_result(range(os.stat_result.n_fields)) >>> st os.stat_result(st_mode=0, st_ino=1, st_dev=2, st_nlink=3, st_uid=4, st_gid=5, st_size=6, st_atime=10, st_mtime=11, st_ctime=12) # make the field names and values match >>> st[7] 7 >>> st.st_atime 10 >>> st = os.stat_result(tuple(range(10)) + (7.1, 8.2, 9.3)) >>> st os.stat_result(st_mode=0, st_ino=1, st_dev=2, st_nlink=3, st_uid=4, st_gid=5, st_size=6, st_atime=7.1, st_mtime=8.2, st_ctime=9.3) >>> st[7] # index = 7 is int 7 >>> st.st_atime # index = 10 is float 7.1 >>> os.stat(os.curdir) os.stat_result(st_mode=16877, st_ino=429294614, st_dev=16777232, st_nlink=58, st_uid=501, st_gid=20, st_size=1856, st_atime=1784996316.4868717, st_mtime=1784996316.472091, st_ctime=1784996316.472091) Without the custom statresult_repr, the generic will be used, which is not that legible. >>> st = os.stat_result(range(os.stat_result.n_fields)) >>> st 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) >>> os.stat(os.curdir) os.stat_result(st_mode=16877, st_ino=429294614, st_dev=16777232, st_nlink=58, st_uid=501, st_gid=20, st_size=1856, =1784996316, =1784996316, =1784996316) Fixes #154387 Issue: gh-154387

Open Graph Description: Walk the members alongside the visible slots and label unnamed slots positionally as <unnamed@N>, which is correct regardless of where the unnamed fields sit among the visible ones. Before th...

X Description: Walk the members alongside the visible slots and label unnamed slots positionally as &lt;unnamed@N&gt;, which is correct regardless of where the unnamed fields sit among the visible ones. B...

Opengraph URL: https://github.com/python/cpython/pull/154687

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:96a1cc7c-e249-806a-50c0-9edb2cd72c36
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id97FE:399E4B:3A8BA4A:4DA2B76:6B021597
html-safe-noncef1ed205d169cc5eada9849d2686dc4622c27c941f18b6cc167f5053ad2e617f8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5N0ZFOjM5OUU0QjozQThCQTRBOjREQTJCNzY6NkIwMjE1OTciLCJ2aXNpdG9yX2lkIjoiMTQ0MjAzOTk5MTU5NjM1NzAxNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac9c3c8892452eb6d53debcdfa79a9e87bdbd2e52aaf22eb52594029306a85b603
hovercard-subject-tagpull_request:4131999914
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/154687/files
twitter:imagehttps://avatars.githubusercontent.com/u/16078332?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/16078332?s=400&v=4
og:image:altWalk the members alongside the visible slots and label unnamed slots positionally as <unnamed@N>, which is correct regardless of where the unnamed fields sit among the visible ones. Before th...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/154687/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F154687%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F154687%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/154687/files
Reloadhttps://github.com/python/cpython/pull/154687/files
Reloadhttps://github.com/python/cpython/pull/154687/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
XuehaiPanhttps://github.com/XuehaiPan
python:mainhttps://github.com/python/cpython/tree/main
XuehaiPan:fix-structseq-unnamedhttps://github.com/XuehaiPan/cpython/tree/fix-structseq-unnamed
Conversation 2 https://github.com/python/cpython/pull/154687
Commits 19 https://github.com/python/cpython/pull/154687/commits
Checks 53 https://github.com/python/cpython/pull/154687/checks
Files changed https://github.com/python/cpython/pull/154687/files
Please reload this pagehttps://github.com/python/cpython/pull/154687/files
gh-154387: fix structseq_repr by labeling unnamed fields in repr as https://github.com/python/cpython/pull/154687/files#top
Show all changes 19 commits https://github.com/python/cpython/pull/154687/files
34b2b44 fix(structseq): label unnamed fields in repr as XuehaiPan Jul 25, 2026 https://github.com/python/cpython/pull/154687/commits/34b2b44a619da95e25ad05b0f4d83a75a6786ac7
23411b4 fix: fix missing import due to git rebase XuehaiPan Jul 25, 2026 https://github.com/python/cpython/pull/154687/commits/23411b4fe0a6f7551819bf032013a1025e3c4fe0
9b3f8fe test(structseq): cover a hidden named field in the interspersed test XuehaiPan Jul 25, 2026 https://github.com/python/cpython/pull/154687/commits/9b3f8fe293d09176f039a59756425f2624461957
227e089 fix: remove `test_` prefix for functions in `_testcapi` XuehaiPan Jul 25, 2026 https://github.com/python/cpython/pull/154687/commits/227e08904d8741bb7b10a9e51b6d00c15ec0e6cd
50a2e22 feat(os): custom repr for os.stat_result showing time fields by name XuehaiPan Jul 25, 2026 https://github.com/python/cpython/pull/154687/commits/50a2e22bde628a00b15f9a3e67412e78a2e476ef
59e2238 Merge remote-tracking branch 'upstream/main' into fix-structseq-unnamed XuehaiPan Jul 25, 2026 https://github.com/python/cpython/pull/154687/commits/59e2238d7dcafdf309f0d156c89cbb783243384b
ee2e5f8 Merge remote-tracking branch 'upstream/main' into fix-structseq-unnamed XuehaiPan Jul 26, 2026 https://github.com/python/cpython/pull/154687/commits/ee2e5f86249497bf1ff44fb0518e736b4fda267a
500cdae Merge remote-tracking branch 'upstream/main' into fix-structseq-unnamed XuehaiPan Jul 26, 2026 https://github.com/python/cpython/pull/154687/commits/500cdae9a7fe74c85049fc2276a034ea2577e05b
9fde8ce ci: try fix ci XuehaiPan Jul 26, 2026 https://github.com/python/cpython/pull/154687/commits/9fde8ce629373ebd58038015c500eb5f5a90a004
61c9236 Merge remote-tracking branch 'upstream/main' into fix-structseq-unnamed XuehaiPan Aug 4, 2026 https://github.com/python/cpython/pull/154687/commits/61c92363cc639ac76354ee53cfe25b9f931c5281
8a3c65e ci: try fix ci XuehaiPan Aug 4, 2026 https://github.com/python/cpython/pull/154687/commits/8a3c65e1e90fa04b190f386377956c102930bc12
49ea69f Merge remote-tracking branch 'upstream/main' into fix-structseq-unnamed XuehaiPan Aug 4, 2026 https://github.com/python/cpython/pull/154687/commits/49ea69ff3acbf78daf26843120d8de4179866c47
60d7ef1 Merge remote-tracking branch 'upstream/main' into fix-structseq-unnamed XuehaiPan Aug 13, 2026 https://github.com/python/cpython/pull/154687/commits/60d7ef12c0752e5503d39165e29ec3bb62bcaa64
ed881b7 Merge branch 'main' into fix-structseq-unnamed XuehaiPan Aug 16, 2026 https://github.com/python/cpython/pull/154687/commits/ed881b7c100fd350862eba5ae0560dd93a5fdd8e
0247aa7 Merge branch 'main' into fix-structseq-unnamed XuehaiPan Sep 1, 2026 https://github.com/python/cpython/pull/154687/commits/0247aa797050e7ed63a3fb7c5676e24dd4f9e868
969e56f Merge branch 'main' into fix-structseq-unnamed XuehaiPan Sep 27, 2026 https://github.com/python/cpython/pull/154687/commits/969e56ff7c0f837a1c5399dc6c979a1f052656c1
ca351cb Merge remote-tracking branch 'upstream/main' into fix-structseq-unnamed XuehaiPan Oct 29, 2026 https://github.com/python/cpython/pull/154687/commits/ca351cb60b6cdd6e1a1c750140f39bbcef4b1c3e
89c0657 Merge remote-tracking branch 'upstream/main' into fix-structseq-unnamed XuehaiPan Nov 2, 2026 https://github.com/python/cpython/pull/154687/commits/89c0657b00b2046acff738ea6e91d684dcea702c
c13e4f2 Merge remote-tracking branch 'upstream/main' into fix-structseq-unnamed XuehaiPan Nov 17, 2026 https://github.com/python/cpython/pull/154687/commits/c13e4f2aee512437fbbf617119ac98db04bbdbbf
Clear filters https://github.com/python/cpython/pull/154687/files
Please reload this pagehttps://github.com/python/cpython/pull/154687/files
Please reload this pagehttps://github.com/python/cpython/pull/154687/files
test_structseq.py https://github.com/python/cpython/pull/154687/files#diff-4a637803c745f86a5ed3a3bb336b12697a2635ab209994b8c989b8cfae0085ef
2026-07-25-14-06-33.gh-issue-154387.t2fIXs.rst https://github.com/python/cpython/pull/154687/files#diff-abcd56242bbd375102412d73fbc94ce464e483799f5b1d70d907e81991e5783c
_testcapimodule.c https://github.com/python/cpython/pull/154687/files#diff-b2d7540efa4f376350ef77b923a6dfcc54bb90424970477f66275f19bad0d30f
posixmodule.c https://github.com/python/cpython/pull/154687/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
structseq.c https://github.com/python/cpython/pull/154687/files#diff-6088e5bc32426d02181ea56f5c4acbfc2fef3094c476b8081b22772fe205ccbd
Lib/test/test_structseq.pyhttps://github.com/python/cpython/pull/154687/files#diff-4a637803c745f86a5ed3a3bb336b12697a2635ab209994b8c989b8cfae0085ef
View file https://github.com/python/cpython/blob/c13e4f2aee512437fbbf617119ac98db04bbdbbf/Lib/test/test_structseq.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154687/{{ revealButtonHref }}
https://github.com/python/cpython/pull/154687/files#diff-4a637803c745f86a5ed3a3bb336b12697a2635ab209994b8c989b8cfae0085ef
https://github.com/python/cpython/pull/154687/files#diff-4a637803c745f86a5ed3a3bb336b12697a2635ab209994b8c989b8cfae0085ef
https://github.com/python/cpython/pull/154687/files#diff-4a637803c745f86a5ed3a3bb336b12697a2635ab209994b8c989b8cfae0085ef
https://github.com/python/cpython/pull/154687/files#diff-4a637803c745f86a5ed3a3bb336b12697a2635ab209994b8c989b8cfae0085ef
Misc/NEWS.d/next/Core_and_Builtins/2026-07-25-14-06-33.gh-issue-154387.t2fIXs.rsthttps://github.com/python/cpython/pull/154687/files#diff-abcd56242bbd375102412d73fbc94ce464e483799f5b1d70d907e81991e5783c
View file https://github.com/python/cpython/blob/c13e4f2aee512437fbbf617119ac98db04bbdbbf/Misc/NEWS.d/next/Core_and_Builtins/2026-07-25-14-06-33.gh-issue-154387.t2fIXs.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154687/{{ revealButtonHref }}
Modules/_testcapimodule.chttps://github.com/python/cpython/pull/154687/files#diff-b2d7540efa4f376350ef77b923a6dfcc54bb90424970477f66275f19bad0d30f
View file https://github.com/python/cpython/blob/c13e4f2aee512437fbbf617119ac98db04bbdbbf/Modules/_testcapimodule.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154687/{{ revealButtonHref }}
https://github.com/python/cpython/pull/154687/files#diff-b2d7540efa4f376350ef77b923a6dfcc54bb90424970477f66275f19bad0d30f
https://github.com/python/cpython/pull/154687/files#diff-b2d7540efa4f376350ef77b923a6dfcc54bb90424970477f66275f19bad0d30f
https://github.com/python/cpython/pull/154687/files#diff-b2d7540efa4f376350ef77b923a6dfcc54bb90424970477f66275f19bad0d30f
https://github.com/python/cpython/pull/154687/files#diff-b2d7540efa4f376350ef77b923a6dfcc54bb90424970477f66275f19bad0d30f
Modules/posixmodule.chttps://github.com/python/cpython/pull/154687/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
View file https://github.com/python/cpython/blob/c13e4f2aee512437fbbf617119ac98db04bbdbbf/Modules/posixmodule.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154687/{{ revealButtonHref }}
https://github.com/python/cpython/pull/154687/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
https://github.com/python/cpython/pull/154687/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
https://github.com/python/cpython/pull/154687/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
https://github.com/python/cpython/pull/154687/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
https://github.com/python/cpython/pull/154687/files#diff-b5b7e4f5599916b2018e911ef423f9d3fd46cb71268e1a73c74a1c9ae2cb6791
Objects/structseq.chttps://github.com/python/cpython/pull/154687/files#diff-6088e5bc32426d02181ea56f5c4acbfc2fef3094c476b8081b22772fe205ccbd
View file https://github.com/python/cpython/blob/c13e4f2aee512437fbbf617119ac98db04bbdbbf/Objects/structseq.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154687/{{ revealButtonHref }}
https://github.com/python/cpython/pull/154687/files#diff-6088e5bc32426d02181ea56f5c4acbfc2fef3094c476b8081b22772fe205ccbd
https://github.com/python/cpython/pull/154687/files#diff-6088e5bc32426d02181ea56f5c4acbfc2fef3094c476b8081b22772fe205ccbd
https://github.com/python/cpython/pull/154687/files#diff-6088e5bc32426d02181ea56f5c4acbfc2fef3094c476b8081b22772fe205ccbd
https://github.com/python/cpython/pull/154687/files#diff-6088e5bc32426d02181ea56f5c4acbfc2fef3094c476b8081b22772fe205ccbd
Please reload this pagehttps://github.com/python/cpython/pull/154687/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.