Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ Process-wide parameters
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.

.. deprecated-removed:: 3.13 3.15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should postpone hard deprecation until there is a non-deprecated replacement that works in all maintained Python versions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PySys_GetObject() works on all Python versions, it's not deprecated: https://docs.python.org/dev/c-api/sys.html#c.PySys_GetObject

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use pythoncapi-compat to get PyConfig_Get() on Python 3.13 and older.

Get :data:`sys.executable` instead.
Use ``PySys_GetObject("executable")`` (:data:`sys.executable`) or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that PyConfig_Get("executable") is more preferable in a new code, isn't it?

PySys_GetObject() will be deprecated in future (it returns a borrowed reference and silences errors).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PySys_GetObject() works on all Python versions, whereas PyConfig_Get() is new in Python 3.14. The note can be updated once PySys_GetObject() will be deprecated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should suggest first what will work in future versions. We do not want users to rewrite the same code twice (and curse us twice).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PySys_GetObject() works on all Python versions, whereas PyConfig_Get() is new in Python 3.14.

I don't understand; this PR is for the 3.14 docs, so it should be ok to mention new-in-3.14 APIs here, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, I would prefer to provide a replacement working on old Python versions as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR to use only PyConfig_Get().

``PyConfig_Get("executable")`` instead.


.. c:function:: wchar_t* Py_GetPrefix()
Expand All @@ -644,8 +645,11 @@ Process-wide parameters
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.

.. deprecated-removed:: 3.13 3.15
Get :data:`sys.base_prefix` instead, or :data:`sys.prefix` if
:ref:`virtual environments <venv-def>` need to be handled.
Use ``PySys_GetObject("base_prefix")`` (:data:`sys.base_prefix`) or
``PyConfig_Get("base_prefix")`` instead. Use
``PySys_GetObject("prefix")`` (:data:`sys.prefix`) or
``PyConfig_Get("prefix")`` if :ref:`virtual environments <venv-def>` need
to be handled.


.. c:function:: wchar_t* Py_GetExecPrefix()
Expand Down Expand Up @@ -690,8 +694,11 @@ Process-wide parameters
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.

.. deprecated-removed:: 3.13 3.15
Get :data:`sys.base_exec_prefix` instead, or :data:`sys.exec_prefix` if
:ref:`virtual environments <venv-def>` need to be handled.
Use ``PySys_GetObject("base_exec_prefix")``
(:data:`sys.base_exec_prefix`) or ``PyConfig_Get("base_exec_prefix")``
instead. Use ``PySys_GetObject("exec_prefix")`` (:data:`sys.exec_prefix`)
or ``PyConfig_Get("exec_prefix")`` if :ref:`virtual environments
<venv-def>` need to be handled.


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

.. deprecated-removed:: 3.13 3.15
Get :data:`sys.executable` instead.
Use ``PySys_GetObject("executable")`` (:data:`sys.executable`) or
``PyConfig_Get("executable")`` instead.


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

.. deprecated-removed:: 3.13 3.15
Get :data:`sys.path` instead.
Use ``PySys_GetObject("path")`` (:data:`sys.path`)
or ``PyConfig_Get("module_search_paths")`` instead.


.. c:function:: const char* Py_GetVersion()
Expand Down Expand Up @@ -926,8 +935,8 @@ Process-wide parameters
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.

.. deprecated-removed:: 3.13 3.15
Get :c:member:`PyConfig.home` or :envvar:`PYTHONHOME` environment
variable instead.
Use :c:func:`PyConfig_Get("home") <PyConfig_Get>`
or the :envvar:`PYTHONHOME` environment variable instead.


.. _threads:
Expand Down
28 changes: 19 additions & 9 deletions Doc/deprecations/c-api-pending-removal-in-3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,30 @@ Pending removal in Python 3.15
:c:func:`PyWeakref_GetRef` on Python 3.12 and older.
* :c:type:`Py_UNICODE` type and the :c:macro:`!Py_UNICODE_WIDE` macro:
Use :c:type:`wchar_t` instead.
* Python initialization functions:
* Python initialization functions, deprecated in Python 3.13:

* :c:func:`PySys_ResetWarnOptions`:
Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead.
* :c:func:`Py_GetExecPrefix`:
Get :data:`sys.base_exec_prefix` and :data:`sys.exec_prefix` instead.
Use ``PySys_GetObject("base_exec_prefix")`` (:data:`sys.base_exec_prefix`)
or ``PyConfig_Get("base_exec_prefix")`` instead. Use
``PySys_GetObject("exec_prefix")`` (:data:`sys.exec_prefix`) or
``PyConfig_Get("exec_prefix")`` if :ref:`virtual environments <venv-def>`
need to be handled.
* :c:func:`Py_GetPath`:
Get :data:`sys.path` instead.
Use ``PySys_GetObject("path")`` (:data:`sys.path`)
or ``PyConfig_Get("module_search_paths")`` instead.
* :c:func:`Py_GetPrefix`:
Get :data:`sys.base_prefix` and :data:`sys.prefix` instead.
Use ``PySys_GetObject("base_prefix")`` (:data:`sys.base_prefix`) or
``PyConfig_Get("base_prefix")`` instead. Use ``PySys_GetObject("prefix")``
(:data:`sys.prefix`) or ``PyConfig_Get("prefix")`` if :ref:`virtual
environments <venv-def>` need to be handled.
* :c:func:`Py_GetProgramFullPath`:
Get :data:`sys.executable` instead.
Use ``PySys_GetObject("executable")`` (:data:`sys.executable`)
or ``PyConfig_Get("executable")`` instead.
* :c:func:`Py_GetProgramName`:
Get :data:`sys.executable` instead.
Use ``PySys_GetObject("executable")`` (:data:`sys.executable`)
or ``PyConfig_Get("executable")`` instead.
* :c:func:`Py_GetPythonHome`:
Get :c:func:`PyConfig_Get("home") <PyConfig_Get>`
Use :c:func:`PyConfig_Get("home") <PyConfig_Get>`
or the :envvar:`PYTHONHOME` environment variable instead.

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

The :c:func:`Py_InitializeFromConfig` API should be used with
:c:type:`PyConfig` instead.
Expand Down
Loading