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

Skip to content

Commit a335c23

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() and uses sys.prefix instead of Py_GetPrefix().
1 parent 85b0b0c commit a335c23

File tree

7 files changed

+57
-12
lines changed

7 files changed

+57
-12
lines changed

Doc/c-api/init.rst

Lines changed: 19 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 :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 :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 :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 :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 :data:`sys.path` instead.
550+
536551

537552
.. c:function:: const char* Py_GetVersion()
538553
@@ -616,6 +631,10 @@ 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` or :envvar:`PYTHONHOME` environment
636+
variable instead.
637+
619638
620639
.. _threads:
621640

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 :data:`sys.warnoptions` and :data:`warnings.filters` 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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,20 @@ 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+
clear :data:`sys.warnoptions` and :data:`warnings.filters` instead.
364+
* :c:func:`Py_GetExecPrefix`: get :data:`sys.exec_prefix` instead.
365+
* :c:func:`Py_GetPath`: get :data:`sys.path` instead.
366+
* :c:func:`Py_GetPrefix`: get :data:`sys.prefix` instead.
367+
* :c:func:`Py_GetProgramFullPath`: get :data:`sys.executable` instead.
368+
* :c:func:`Py_GetProgramName`: get :data:`sys.executable` instead.
369+
* :c:func:`Py_GetPythonHome`: get :c:member:`PyConfig.home` or
370+
:envvar:`PYTHONHOME` environment variable instead.
371+
372+
(Contributed by Victor Stinner in :gh:`105145`.)
373+
360374
Removed
361375
-------
362376

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: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,10 @@ _get_tcl_lib_path(void)
130130
static int already_checked = 0;
131131

132132
if (already_checked == 0) {
133-
PyObject *prefix;
134133
struct stat stat_buf;
135134
int stat_return_value;
136135

137-
prefix = PyUnicode_FromWideChar(Py_GetPrefix(), -1);
136+
PyObject *prefix = PySys_GetObject("prefix"); // borrowed reference
138137
if (prefix == NULL) {
139138
return NULL;
140139
}
@@ -3289,8 +3288,8 @@ PyInit__tkinter(void)
32893288

32903289
/* This helps the dynamic loader; in Unicode aware Tcl versions
32913290
it also helps Tcl find its encodings. */
3292-
uexe = PyUnicode_FromWideChar(Py_GetProgramName(), -1);
3293-
if (uexe) {
3291+
uexe = PySys_GetObject("executable"); // borrowed reference
3292+
if (uexe && PyUnicode_Check(uexe)) { // sys.executable can be None
32943293
cexe = PyUnicode_EncodeFSDefault(uexe);
32953294
if (cexe) {
32963295
#ifdef MS_WINDOWS
@@ -3329,7 +3328,6 @@ PyInit__tkinter(void)
33293328
#endif /* MS_WINDOWS */
33303329
}
33313330
Py_XDECREF(cexe);
3332-
Py_DECREF(uexe);
33333331
}
33343332

33353333
if (PyErr_Occurred()) {

0 commit comments

Comments
 (0)
0