Title: Deprecate the tuple API (`object[index]`) of structseq types (ex: os.stat_result) · Issue #155358 · python/cpython · GitHub
Open Graph Title: Deprecate the tuple API (`object[index]`) of structseq types (ex: os.stat_result) · Issue #155358 · python/cpython
X Title: Deprecate the tuple API (`object[index]`) of structseq types (ex: os.stat_result) · Issue #155358 · python/cpython
Description: Hi, I propose deprecating the tuple API (object[index]) of the following structseq objects: _interpchannels.ChannelInfo _lsprof.profiler_entry _lsprof.profiler_subentry _thread._ExceptHookArgs grp.struct_group os.sched_param os.stat_resu...
Open Graph Description: Hi, I propose deprecating the tuple API (object[index]) of the following structseq objects: _interpchannels.ChannelInfo _lsprof.profiler_entry _lsprof.profiler_subentry _thread._ExceptHookArgs grp....
X Description: Hi, I propose deprecating the tuple API (object[index]) of the following structseq objects: _interpchannels.ChannelInfo _lsprof.profiler_entry _lsprof.profiler_subentry _thread._ExceptHookArgs grp....
Opengraph URL: https://github.com/python/cpython/issues/155358
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Deprecate the tuple API (`object[index]`) of structseq types (ex: os.stat_result)","articleBody":"Hi,\n\nI propose deprecating the tuple API (`object[index]`) of the following structseq objects:\n\n* `_interpchannels.ChannelInfo`\n* `_lsprof.profiler_entry`\n* `_lsprof.profiler_subentry`\n* `_thread._ExceptHookArgs`\n* `grp.struct_group`\n* `os.sched_param`\n* `os.stat_result`\n* `os.statvfs_result`\n* `os.terminal_size`\n* `os.times_result`\n* `os.uname_result`\n* `os.waitid_result`\n* `pwd.struct_passwd`\n* `resource.struct_rusage`\n* `signal.struct_siginfo`\n* `sys.UnraisableHookArgs`\n* `sys._emscripten_info`\n* `sys.asyncgen_hooks`\n* `sys.flags`\n* `sys.float_info`\n* `sys.getwindowsversion`\n* `sys.hash_info`\n* `sys.int_info`\n\nThe tuple API of the following structseq objects is kept, since it's useful:\n\n* `sys.version_info`: for example, `sys.version_info[:2]` is commonly used.\n* `curses.ncurses_version`: same rationale than `sys.version_info`.\n* `time.struct_time`: for example, `y, m, d, hh, mm, ss = struct_time[:6]` is used to unpack a time struct.\n\n---\n\nIn the early days of Python, it was tedious to create an object with attributes in C. So to keep the implementation simple, many functions returned simply a tuple (trivial to build in C). Example on Python 1.5 (yes, Python version one!):\n\n```\n$ ./python\nPython 1.5.2 (#1, Aug 7 2026, 17:03:12) [GCC 16.1.1 20260515 (Red Hat 16.1.1-2) on linux7\nCopyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam\n>>> import os\n>>> st=os.stat(\".\")\n>>> type(st)\n\u003ctype 'tuple'>\n>>> st\n(16877, 60670004, 43, 1, 1000, 1000, 476, 1786114992, 1786114992, 1786114992)\n```\n\nThe `stat` module provides indices to state struct members:\n\n```\n# Indices for stat struct members in the tuple returned by os.stat()\n\nST_MODE = 0\nST_INO = 1\nST_DEV = 2\nST_NLINK = 3\nST_UID = 4\nST_GID = 5\nST_SIZE = 6\nST_ATIME = 7\nST_MTIME = 8\nST_CTIME = 9\n```\n\nFor example, `st[stat.ST_INO]` gets the inode number.\n\n---\n\nOver time, APIs became more and more complex and the **`structseq`** type was added to Python 2.2. It preserves the tuple API (`object[index]`), but adds also named attributes to object.\n\nFor example, `st.st_ino` gets the inode number. The tuple API is kept for backward compatibility.\n\n`os.stat_result` has a complex history:\n\n* At the beginning, `os.stat()` simply returned a tuple of 10 integers.\n* Python 2.2 changed `os.stat()` result type to `os.stat_result` to give access to attribute by name, but keep the tuple API for **backward compatibility**.\n* Python 2.3 added `os.stat_float_times(True)` which allowed to get timestamps as float: timestamps remain integers by default. Only `st.st_atime`, `st.st_ctime` and `st.st_mtime` can be float. `st[7]`, `st[8]` and `st[9]` are always integers, for **backward compatibility**.\n* Python 2.5 switched timestamps to float by default.\n* Python 3.3 added `st_atime_ns`, `st_ctime_ns` and `st_mtime_ns`.\n\nSo timestamps are stored in 3 formats in Python 3.15:\n\n* integer (tuple API: seconds) for backward compatibility with Python 2.2 and older (yep, that's quite old!);\n* float for `st_[acm]time` (seconds);\n* integer for `st_[acm]time_ns` (nanoseconds).\n\nI would prefer to deprecate this tuple API. It's time to move on to named attributes introduced in Python 2.3!\n\n---\n\nLast years, new `structseq` objects were added with the tuple API even if these new objects didn't have to provide a backward compatibility with a previous tuple API. It's just because `structseq` doesn't give the choice, the tuple API is always provided.\n\n---\n\nBy the way, later, `_PyNamespace_New()` and `types.SimpleNamespace` were added to Python 3.3 to create a simple object with attributes from a dictionary (attribute name => attribute value). For example, `sys.implementation` uses this API.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-155359\n* gh-155362\n* gh-155364\n* gh-155366\n* gh-155367\n* gh-155368\n* gh-155510\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/vstinner","@type":"Person","name":"vstinner"},"datePublished":"2026-08-07T17:59:40Z","url":"https://github.com/python/cpython/issues/155358"}
| 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:326d4de4-49de-f5b4-3bdc-96c9c07022de |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D182:4BB79:40F0EA9:52D50CB:6B022F3A |
| html-safe-nonce | bbc2725bf0307b0df19e469735ecd410eed06eea8ffbc15c31da93e6a5136c12 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTgyOjRCQjc5OjQwRjBFQTk6NTJENTBDQjo2QjAyMkYzQSIsInZpc2l0b3JfaWQiOiI5MTMxMjM5NTU3MDE3MjUxNjQyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 71203f7aba9ee0e44e2e0803af153294812569ceadf13be561f4df6de5a3d468 |
| hovercard-subject-tag | issue:5092739998 |
| 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/155358/issue_layout |
| twitter:image | https://opengraph.githubassets.com/09fa05638d881bade2aea6feddbe8dee387763c55bfe057a52fbf7265387d775/python/cpython/issues/155358 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/09fa05638d881bade2aea6feddbe8dee387763c55bfe057a52fbf7265387d775/python/cpython/issues/155358 |
| og:image:alt | Hi, I propose deprecating the tuple API (object[index]) of the following structseq objects: _interpchannels.ChannelInfo _lsprof.profiler_entry _lsprof.profiler_subentry _thread._ExceptHookArgs grp.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vstinner |
| 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