This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [C API] Deprecate legacy API for configure Python initialization
Type: Stage: resolved
Components: C API, Documentation Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: corona10, docs@python, joukewitteveen, vstinner
Priority: normal Keywords: patch

Created on 2021-05-12 10:20 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26060 merged vstinner, 2021-05-12 10:28
PR 24876 joukewitteveen, 2021-05-12 10:29
PR 26083 merged corona10, 2021-05-12 21:43
PR 26084 merged vstinner, 2021-05-12 22:47
PR 26085 merged corona10, 2021-05-12 23:31
PR 28974 merged vstinner, 2021-10-15 11:10
Messages (8)
msg393499 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-12 10:20
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.
msg393550 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-12 22:00
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.
msg393551 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-12 22:49
"""
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/
msg393553 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-13 00:31
commit 6cd0446ef72c6676b292d7f54b1ddb8ae5e1fb8d
Author: Victor Stinner <vstinner@python.org>
Date:   Wed May 12 23:59:25 2021 +0200

    bpo-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 a0ccc404ca649c2a1635511a09df2454e47b4d66
Author: Dong-hee Na <donghee.na@python.org>
Date:   Thu May 13 08:22:18 2021 +0900

    bpo-44113: Update __xxtestfuzz not to use Py_SetProgramName (GH-26083)

commit ec7c09b9bc9a8f333a0295b41ea88986c320448c
Author: Victor Stinner <vstinner@python.org>
Date:   Thu May 13 02:27:56 2021 +0200

    bpo-44113: Fix compiler warning in PySys_AddWarnOption() (GH-26084)
    
    Ignore Py_DEPRECATED() warning on purpose.
msg393641 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-14 11:57
commit 7565586724692e2ad164d770af9675f7a261fe3a
Author: Dong-hee Na <donghee.na@python.org>
Date:   Thu May 13 10:19:46 2021 +0900

    bpo-44113: Update fromzenmain not to use Py_SetProgramName (GH-26085)
msg393647 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-14 12:21
> 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().
msg393648 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-14 12:21
Thanks for the help Dong-hee ;-) I close the issue, functions are now deprecated.
msg404005 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-15 11:43
New changeset a7f8dfd25a167ccfde9996c499fa38a2aba60022 by Victor Stinner in branch 'main':
bpo-44113: Move the What's New entry to Deprecate section (GH-28974)
https://github.com/python/cpython/commit/a7f8dfd25a167ccfde9996c499fa38a2aba60022
History
Date User Action Args
2022-04-11 14:59:45adminsetgithub: 88279
2021-10-15 11:43:51vstinnersetmessages: + msg404005
2021-10-15 11:10:22vstinnersetpull_requests: + pull_request27262
2021-05-14 12:21:54vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg393648

stage: patch review -> resolved
2021-05-14 12:21:21vstinnersetmessages: + msg393647
2021-05-14 11:57:21vstinnersetmessages: + msg393641
2021-05-13 00:31:40vstinnersetmessages: + msg393553
2021-05-12 23:31:39corona10setpull_requests: + pull_request24724
2021-05-12 22:49:09vstinnersetmessages: + msg393551
2021-05-12 22:47:45vstinnersetpull_requests: + pull_request24723
2021-05-12 22:00:44vstinnersetmessages: + msg393550
2021-05-12 21:43:09corona10setnosy: + corona10
pull_requests: + pull_request24722
2021-05-12 10:29:16joukewitteveensetnosy: + joukewitteveen
pull_requests: + pull_request24701
2021-05-12 10:28:48vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request24700
2021-05-12 10:20:54vstinnercreate