8000 gh-105145: Deprecate Py_GetPath() function · python/cpython@5306a2b · GitHub
[go: up one dir, main page]

Skip to content

Commit 5306a2b

Browse files
committed
gh-105145: Deprecate Py_GetPath() function
Deprecate old Python initialization functions: * PySys_ResetWarnOptions() * Py_GetExecPrefix() * Py_GetPath() * Py_GetPrefix() * Py_GetProgramFullPath() * Py_GetProgramName() * Py_GetPythonHome() _tkinter uses sys.executable instead of Py_GetProgramName().
1 parent 424049c commit 5306a2b

File tree

7 files changed

+53
-10
lines changed

7 files changed

+53
-10
lines changed

Doc/c-api/init.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ Process-wide parameters
430430
.. versionchanged:: 3.10
431431
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
432432

433+
.. deprecated-removed:: 3.13 3.15
434+
Get :c:member:`PyConfig.program_name` or :data:`sys.executable` instead.
435+
433436

434437
.. c:function:: wchar_t* Py_GetPrefix()
435438
@@ -449,6 +452,9 @@ Process-wide parameters
449452
.. versionchanged:: 3.10
450453
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
451454

455+
.. deprecated-removed:: 3.13 3.15
456+
Get :c:member:`PyConfig.prefix` or :data:`sys.prefix` instead.
457+
452458

453459
.. c:function:: wchar_t* Py_GetExecPrefix()
454460
@@ -490,6 +496,9 @@ Process-wide parameters
490496
.. versionchanged:: 3.10
491497
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
492498

499+
.. deprecated-removed:: 3.13 3.15
500+
Get :c:member:`PyConfig.exec_prefix` or :data:`sys.exec_prefix` instead.
501+
493502

494503
.. c:function:: wchar_t* Py_GetProgramFullPath()
495504
@@ -508,6 +517,9 @@ Process-wide parameters
508517
.. versionchanged:: 3.10
509518
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
510519

520+
.. deprecated-removed:: 3.13 3.15
521+
Get :c:member:`PyConfig.executable` or :data:`sys.executable` instead.
522+
511523

512524
.. c:function:: wchar_t* Py_GetPath()
513525
@@ -533,6 +545,9 @@ Process-wide parameters
533545
.. versionchanged:: 3.10
534546
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
535547

548+
.. deprecated-removed:: 3.13 3.15
549+
Get :c:member:`PyConfig.module_search_paths` or :data:`sys.path` instead.
550+
536551

537552
.. c:function:: const char* Py_GetVersion()
538553
@@ -616,6 +631,9 @@ Process-wide parameters
616631
.. versionchanged:: 3.10
617632
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
618633
634+
.. deprecated-removed:: 3.13 3.15
635+
Get :c:member:`PyConfig.home` instead.
636+
619637
620638
.. _threads:
621639

Doc/c-api/sys.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ accessible to C code. They all work with the current interpreter thread's
237237
Reset :data:`sys.warnoptions` to an empty list. This function may be
238238
called prior to :c:func:`Py_Initialize`.
239239
240+
.. deprecated-removed:: 3.13 3.15
241+
Clear :c:member:`PyConfig.warnoptions` or :data:`sys.warnoptions` instead.
242+
240243
.. c:function:: void PySys_WriteStdout(const char *format, ...)
241244
242245
Write the output string described by *format* to :data:`sys.stdout`. No

Doc/whatsnew/3.13.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,18 @@ Deprecated
357357
``PY_UNICODE_TYPE`` are just aliases to ``wchar_t``.
358358
(Contributed by Victor Stinner in :gh:`105156`.)
359359

360+
* Deprecate old Python initialization functions:
361+
362+
* :c:func:`PySys_ResetWarnOptions`
363+
* :c:func:`Py_GetExecPrefix`
364+
* :c:func:`Py_GetPath`
365+
* :c:func:`Py_GetPrefix`
366+
* :c:func:`Py_GetProgramFullPath`
367+
* :c:func:`Py_GetProgramName`
368+
* :c:func:`Py_GetPythonHome`
369+
370+
(Contributed by Victor Stinner in :gh:`105145`.)
371+
360372
Removed
361373
-------
362374

Include/pylifecycle.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
3434
PyAPI_FUNC(int) Py_BytesMain(int argc, char **argv);
3535

3636
/* In pathconfig.c */
37-
PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
38-
PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
39-
PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
40-
PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
41-
PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
42-
PyAPI_FUNC(wchar_t *) Py_GetPath(void);
37+
Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
38+
Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
39+
Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
40+
Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
41+
Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
42+
Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetPath(void);
4343
#ifdef MS_WINDOWS
4444
int _Py_CheckPython3(void);
4545
#endif

Include/sysmodule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)
1717
PyAPI_FUNC(void) PySys_FormatStdout(const char *format, ...);
1818
PyAPI_FUNC(void) PySys_FormatStderr(const char *format, ...);
1919

20-
PyAPI_FUNC(void) PySys_ResetWarnOptions(void);
20+
Py_DEPRECATED(3.13) PyAPI_FUNC(void) PySys_ResetWarnOptions(void);
2121

2222
PyAPI_FUNC(PyObject *) PySys_GetXOptions(void);
2323

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Deprecate old Python initialization functions:
2+
3+
* :c:func:`PySys_ResetWarnOptions`
4+
* :c:func:`Py_GetExecPrefix`
5+
* :c:func:`Py_GetPath`
6+
* :c:func:`Py_GetPrefix`
7+
* :c:func:`Py_GetProgramFullPath`
8+
* :c:func:`Py_GetProgramName`
9+
* :c:func:`Py_GetPythonHome`
10+
11+
Patch by Victor Stinner.

Modules/_tkinter.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,8 +3289,8 @@ PyInit__tkinter(void)
32893289

32903290
/* This helps the dynamic loader; in Unicode aware Tcl versions
32913291
it also helps Tcl find its encodings. */
3292-
uexe = PyUnicode_FromWideChar(Py_GetProgramName(), -1);
3293-
if (uexe) {
3292+
uexe = PySys_GetObject("executable"); // borrowed reference
3293+
if (uexe && PyUnicode_Check(uexe)) { // sys.executable can be None
32943294
cexe = PyUnicode_EncodeFSDefault(uexe);
32953295
if (cexe) {
32963296
#ifdef MS_WINDOWS
@@ -3329,7 +3329,6 @@ PyInit__tkinter(void)
33293329
#endif /* MS_WINDOWS */
33303330
}
33313331
Py_XDECREF(cexe);
3332-
Py_DECREF(uexe);
33333332
}
33343333

33353334
if (PyErr_Occurred()) {

0 commit comments

Comments
 (0)
0