Skip to content

Commit c102f8d

Browse files
committed
pythongh-129342: Explain how to replace Py_GetProgramName() in C
1 parent 7ec1742 commit c102f8d

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

Doc/c-api/init.rst

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,8 @@ Process-wide parameters
622622
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
623623
624624
.. deprecated-removed:: 3.13 3.15
625-
Get :data:`sys.executable` instead.
625+
Use ``PySys_GetObject("executable")`` (:data:`sys.executable`) or
626+
``PyConfig_Get("executable")`` instead.
626627
627628
628629
.. c:function:: wchar_t* Py_GetPrefix()
@@ -644,8 +645,11 @@ Process-wide parameters
644645
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
645646
646647
.. deprecated-removed:: 3.13 3.15
647-
Get :data:`sys.base_prefix` instead, or :data:`sys.prefix` if
648-
:ref:`virtual environments <venv-def>` need to be handled.
648+
Use ``PySys_GetObject("base_prefix")`` (:data:`sys.base_prefix`) or
649+
``PyConfig_Get("base_prefix")`` instead. Use
650+
``PySys_GetObject("prefix")`` (:data:`sys.prefix`) or
651+
``PyConfig_Get("prefix")`` if :ref:`virtual environments <venv-def>` need
652+
to be handled.
649653
650654
651655
.. c:function:: wchar_t* Py_GetExecPrefix()
@@ -690,8 +694,11 @@ Process-wide parameters
690694
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
691695

692696
.. deprecated-removed:: 3.13 3.15
693-
Get :data:`sys.base_exec_prefix` instead, or :data:`sys.exec_prefix` if
694-
:ref:`virtual environments <venv-def>` need to be handled.
697+
Use ``PySys_GetObject("base_exec_prefix")``
698+
(:data:`sys.base_exec_prefix`) or ``PyConfig_Get("base_exec_prefix")``
699+
instead. Use ``PySys_GetObject("exec_prefix")`` (:data:`sys.exec_prefix`)
700+
or ``PyConfig_Get("exec_prefix")`` if :ref:`virtual environments
701+
<venv-def>` need to be handled.
695702

696703

697704
.. c:function:: wchar_t* Py_GetProgramFullPath()
@@ -712,7 +719,8 @@ Process-wide parameters
712719
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
713720

714721
.. deprecated-removed:: 3.13 3.15
715-
Get :data:`sys.executable` instead.
722+
Use ``PySys_GetObject("executable")`` (:data:`sys.executable`) or
723+
``PyConfig_Get("executable")`` instead.
716724

717725

718726
.. c:function:: wchar_t* Py_GetPath()
@@ -740,7 +748,8 @@ Process-wide parameters
740748
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
741749

742750
.. deprecated-removed:: 3.13 3.15
743-
Get :data:`sys.path` instead.
751+
Use ``PySys_GetObject("path")`` (:data:`sys.path`)
752+
or ``PyConfig_Get("module_search_paths")`` instead.
744753

745754

746755
.. c:function:: const char* Py_GetVersion()
@@ -926,8 +935,8 @@ Process-wide parameters
926935
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
927936
928937
.. deprecated-removed:: 3.13 3.15
929-
Get :c:member:`PyConfig.home` or :envvar:`PYTHONHOME` environment
930-
variable instead.
938+
Use :c:func:`PyConfig_Get("home") <PyConfig_Get>`
939+
or the :envvar:`PYTHONHOME` environment variable instead.
931940
932941
933942
.. _threads:

Doc/deprecations/c-api-pending-removal-in-3.15.rst

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,30 @@ Pending removal in Python 3.15
1010
:c:func:`PyWeakref_GetRef` on Python 3.12 and older.
1111
* :c:type:`Py_UNICODE` type and the :c:macro:`!Py_UNICODE_WIDE` macro:
1212
Use :c:type:`wchar_t` instead.
13-
* Python initialization functions:
13+
* Python initialization functions, deprecated in Python 3.13:
1414

15-
* :c:func:`PySys_ResetWarnOptions`:
16-
Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead.
1715
* :c:func:`Py_GetExecPrefix`:
18-
Get :data:`sys.base_exec_prefix` and :data:`sys.exec_prefix` instead.
16+
Use ``PySys_GetObject("base_exec_prefix")`` (:data:`sys.base_exec_prefix`)
17+
or ``PyConfig_Get("base_exec_prefix")`` instead. Use
18+
``PySys_GetObject("exec_prefix")`` (:data:`sys.exec_prefix`) or
19+
``PyConfig_Get("exec_prefix")`` if :ref:`virtual environments <venv-def>`
20+
need to be handled.
1921
* :c:func:`Py_GetPath`:
20-
Get :data:`sys.path` instead.
22+
Use ``PySys_GetObject("path")`` (:data:`sys.path`)
23+
or ``PyConfig_Get("module_search_paths")`` instead.
2124
* :c:func:`Py_GetPrefix`:
22-
Get :data:`sys.base_prefix` and :data:`sys.prefix` instead.
25+
Use ``PySys_GetObject("base_prefix")`` (:data:`sys.base_prefix`) or
26+
``PyConfig_Get("base_prefix")`` instead. Use ``PySys_GetObject("prefix")``
27+
(:data:`sys.prefix`) or ``PyConfig_Get("prefix")`` if :ref:`virtual
28+
environments <venv-def>` need to be handled.
2329
* :c:func:`Py_GetProgramFullPath`:
24-
Get :data:`sys.executable` instead.
30+
Use ``PySys_GetObject("executable")`` (:data:`sys.executable`)
31+
or ``PyConfig_Get("executable")`` instead.
2532
* :c:func:`Py_GetProgramName`:
26-
Get :data:`sys.executable` instead.
33+
Use ``PySys_GetObject("executable")`` (:data:`sys.executable`)
34+
or ``PyConfig_Get("executable")`` instead.
2735
* :c:func:`Py_GetPythonHome`:
28-
Get :c:func:`PyConfig_Get("home") <PyConfig_Get>`
36+
Use :c:func:`PyConfig_Get("home") <PyConfig_Get>`
2937
or the :envvar:`PYTHONHOME` environment variable instead.
3038

3139
See also the :c:func:`PyConfig_Get` function.
@@ -40,6 +48,8 @@ Pending removal in Python 3.15
4048
Set :c:member:`PyConfig.program_name` instead.
4149
* :c:func:`!Py_SetPythonHome()`:
4250
Set :c:member:`PyConfig.home` instead.
51+
* :c:func:`PySys_ResetWarnOptions`:
52+
Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead.
4353

4454
The :c:func:`Py_InitializeFromConfig` API should be used with
4555
:c:type:`PyConfig` instead.

0 commit comments

Comments
 (0)