Skip to content

gh-155358: [WIP] Deprecate tuple API of structseq objects - #155359

Draft
vstinner wants to merge 8 commits into
python:mainfrom
vstinner:structseq
Draft

gh-155358: [WIP] Deprecate tuple API of structseq objects#155359
vstinner wants to merge 8 commits into
python:mainfrom
vstinner:structseq

Conversation

@vstinner

@vstinnervstinner commented Aug 7, 2026

Copy link
Copy Markdown
Member

I created this draft PR to check if it's possible to implement the deprecation of the tuple API of structseq types, and check how much stdlib code would be impacted by these deprecations.

pip is not ready for this change:
$ PYTHONWARNINGS=error env/bin/python -Werror -m pip install setuptools -v
Traceback (most recent call last):
File "/home/vstinner/python/main/Lib/runpy.py", line 201, in _run_module_as_main
return _run_code(code, main_globals, None,
"__main__", mod_spec)
File "/home/vstinner/python/main/Lib/runpy.py", line 87, in _run_code
exec(code, run_globals)
~~~~^^^^^^^^^^^^^^^^^^^
File "/home/vstinner/python/main/env/lib/python3.16t/site-packages/pip/__main__.py", line 24, in <module>
sys.exit(_main())
~~~~~^^
File "/home/vstinner/python/main/env/lib/python3.16t/site-packages/pip/_internal/cli/main.py", line 70, in main
cmd_name, cmd_args = parse_command(args)
~~~~~~~~~~~~~^^^^^^
File "/home/vstinner/python/main/env/lib/python3.16t/site-packages/pip/_internal/cli/main_parser.py", line 71, in parse_command
parser = create_main_parser()
File "/home/vstinner/python/main/env/lib/python3.16t/site-packages/pip/_internal/cli/main_parser.py", line 26, in create_main_parser
formatter=UpdatingDefaultsHelpFormatter(),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/home/vstinner/python/main/env/lib/python3.16t/site-packages/pip/_internal/cli/parser.py", line 45, in __init__
kwargs["width"] = shutil.get_terminal_size()[0] - 2
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
DeprecationWarning: tuple API is deprecated, use named attributes
inspect: keep tuple API for 3 namedtuple
@vstinner

Copy link
Copy Markdown
MemberAuthor

pip and setuptools fail with these changes. The issue can be seen in test_cext and test_cppext for example.

pip:

 File "pip/_internal/cli/parser.py", line 45, in __init__
kwargs["width"] = shutil.get_terminal_size()[0] - 2

setuptools:

 File "setuptools/_distutils/file_util.py", line 164, in copy_file
os.utime(dst, (st[ST_ATIME], st[ST_MTIME]))

@vstinner

Copy link
Copy Markdown
MemberAuthor

Notes to replace tuple API with named attributes.

os.stat():

  • st[0] => st.st_mode
  • st[1] => st.st_ino
  • st[2] => st.st_dev
  • st[3] => st.st_nlink
  • st[4] => st.st_uid
  • st[5] => st.st_gid
  • st[6] => st.st_size
  • st[7] => st.st_atime (int => float)
  • st[8] => st.st_mtime (int => `float)
  • st[9] => st.st_ctime (int => float)

pwd:

  • e[0] => e.pw_name
  • e[1] => e.pw_passwd
  • e[2] => e.pw_uid
  • e[3] => e.pw_gid
  • e[4] => e.pw_gecos
  • e[5] => e.pw_dir
  • e[6] => e.pw_shell

grp:

  • e[0] => e.gr_name
  • e[1] => e.gr_passwd
  • e[2] => e.gr_gid
  • e[3] => e.gr_mem

pkgutil.ModuleInfo:

  • e[0] => e.module_finder
  • e[1] => e.name
  • e[2] => e.ispkg

urllib.parse.urlsplit():

  • res[0] => res.scheme
  • res[1] => res.netloc
  • res[2] => res.path
  • res[3] => res.query
  • res[4] => res.fragment

urllib.parse.urlparse():

  • res[0] => res.scheme
  • res[1] => res.netloc
  • res[2] => res.path
  • res[3] => res.params
  • res[4] => res.query
  • res[5] => res.fragment

test.support.script_helper:

  • proc[0] => proc.rc
  • proc[1] => proc.out
  • proc[2] => proc.err

os.statvfs:

  • st[0] => st.f_bsize
  • st[1] => st.f_frsize
  • st[2] => st.f_blocks
  • st[3] => st.f_bfree
  • st[4] => st.f_bavail
  • st[5] => st.f_files
  • st[6] => st.f_ffree
  • st[7] => st.f_favail
  • st[8] => st.f_flag
  • st[9] => st.f_namemax
  • st[10] => st.f_fsid

inspect.stack() items:

  • f[0] => f.frame
  • f[1] => f.filename
  • f[2] => f.lineno
  • f[3] => f.function
  • f[4] => f.code_context

@vstinner

Copy link
Copy Markdown
MemberAuthor

Oh, the setuptools issue has already been fixed in setuptools 84.0.0 with commit pypa/setuptools@39a64a0. Right now, CPython embeds setuptools 79 in Lib/test/wheeldata/setuptools-79.0.1-py3-none-any.whl.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@vstinner