Repository navigation
[C API] Deprecate legacy API for configure Python initialization #88279
Description
Activity
The https://docs.python.org/dev/c-api/init.html documentation lists many functions which is the legacy way to configure the Python initialization. These functions are kept for backward compatibility but have flaws and are less reliable than the new PyConfig API (PEP-587) documented at https://docs.python.org/dev/c-api/init_config.html
I propose to deprecate the legacy functions to configure the Python initialization. Examples:
- Py_SetPath()
- Py_SetProgramName()
- Py_SetPythonHome()
- Py_SetStandardStreamEncoding()
- PySys_AddWarnOption()
- PySys_AddWarnOptionUnicode()
- PySys_AddXOption()
I don't propose to schedule the removal of these functions, only mark them as deprecated in the *documentation*.
Related issue: bpo-43956 "C-API: Incorrect default value for Py_SetProgramName" and PR 24876.
- addeddocsDocumentation in the Doc dirDocumentation in the Doc dir3.11only security fixesonly security fixes
on May 12, 2021 - addeddocsDocumentation in the Doc dirDocumentation in the Doc dir
on May 12, 2021 PyConfig API was added to Python 3.8, so it's now widely available. Python 3.8 always switched to security fixes only phase. So IMO it's ok to deprecate the old API now.
"""
Check warning on line 82 in Python/frozenmain.c
GitHub Actions / Ubuntu
‘Py_SetProgramName’ is deprecated [-Wdeprecated-declarations]
"""Well, Py_FrozenMain() should be rewritten with PyConfig, I want to do that for a long time, but I don't know how to test it. It would be nice to have a very basic test for Py_FrozenMain().
See also:
https://mail.python.org/archives/list/capi-sig@python.org/thread/5QLI3NUP3OSGLCCIBAQOTX4GEJQBWJ6F/commit 6cd0446
Author: Victor Stinner <vstinner@python.org>
Date: Wed May 12 23:59:25 2021 +0200bpo-44113: Deprecate old functions to config Python init (GH-26060) Deprecate the following functions to configure the Python initialization: * PySys_AddWarnOption() * PySys_AddWarnOptionUnicode() * PySys_AddXOption() * PySys_HasWarnOptions() * Py_SetPath() * Py_SetProgramName() * Py_SetPythonHome() * Py_SetStandardStreamEncoding() * _Py_SetProgramFullPath() Use the new PyConfig API of the Python Initialization Configuration instead (PEP-587).commit a0ccc40
Author: Dong-hee Na <donghee.na@python.org>
Date: Thu May 13 08:22:18 2021 +0900bpo-44113: Update __xxtestfuzz not to use Py_SetProgramName (GH-26083)commit ec7c09b
Author: Victor Stinner <vstinner@python.org>
Date: Thu May 13 02:27:56 2021 +0200bpo-44113: Fix compiler warning in PySys_AddWarnOption() (GH-26084) Ignore Py_DEPRECATED() warning on purpose.commit 7565586
Author: Dong-hee Na <donghee.na@python.org>
Date: Thu May 13 10:19:46 2021 +0900bpo-44113: Update fromzenmain not to use Py_SetProgramName (GH-26085)Well, Py_FrozenMain() should be rewritten with PyConfig, I want to do that for a long time, but I don't know how to test it. It would be nice to have a very basic test for Py_FrozenMain().
I created bpo-44131: [C API] Add tests on Py_FrozenMain().
Thanks for the help Dong-hee ;-) I close the issue, functions are now deprecated.
1 remaining item
- added a commit that references this issue
on May 6, 2022 - added a commit that references this issue
on May 7, 2022 - added a commit that references this issue
on Jul 20, 2022 Hey there, I'm unsure if this is the right place to ask - if not, please guide me elsewhere.
How are projects using the limited python API supposed to port away from the deprecated API? The "new" API in
cpython/initconfig.his guarded behind a#ifndef Py_LIMITED_APIand thus not accessible...Can you please make this API available through the limited API, or revert the decision to deprecate this API?
Thanks
The proper place is here: #105145
Apparently, the new API is available widely enough.How are projects using the limited python API supposed to port away from the deprecated API?
I suggest to continue in the dedicated issue: #107954 "No limited C API to customize Python initialization (PyConfig, PEP 587)"
I worked on two projects for the limited C API:
- Stable ABI to configure Python initialization: [PEP 741] gh-107954: Add PyInitConfig C API #110176
- Stable ABI to get the current Python configuration: [PEP 741] gh-107954: Add PyConfig_Get() function #112609 => Add PyConfig_Get() and PyConfig_GetInt() functions capi-workgroup/decisions#3
So far, I had to put this work aside since I had too many things on my plate.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: