https://github.com/python/cpython/commit/eb611a8515d8d7af714b57a5f955a98011000d68
commit: eb611a8515d8d7af714b57a5f955a98011000d68
branch: main
author: Filipe LaĆns <[email protected]>
committer: FFY00 <[email protected]>
date: 2026-03-02T19:19:05Z
summary:
GH-145275: add -X pathconfig_warnings and PYTHON_PATHCONFIG_WARNINGS (#145277)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2026-02-26-21-07-38.gh-issue-145275.qE-3O1.rst
M Doc/using/cmdline.rst
M Python/initconfig.c
diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst
index f4085ff842aea9..84b8575284b793 100644
--- a/Doc/using/cmdline.rst
+++ b/Doc/using/cmdline.rst
@@ -687,6 +687,13 @@ Miscellaneous options
.. versionadded:: 3.14
+ * :samp:`-X pathconfig_warnings={0,1}` if true (``1``) then
+ :ref:`sys-path-init` is allowed to log warnings into stderr.
+ If false (``0``) suppress these warnings. Set to true by default.
+ See also :envvar:`PYTHON_PATHCONFIG_WARNINGS`.
+
+ .. versionadded:: next
+
* :samp:`-X tlbc={0,1}` enables (1, the default) or disables (0)
thread-local
bytecode in builds configured with :option:`--disable-gil`. When
disabled,
this also disables the specializing interpreter. See also
@@ -1354,6 +1361,14 @@ conflict.
.. versionadded:: 3.14
+.. envvar:: PYTHON_PATHCONFIG_WARNINGS
+
+ If true (``1``) then :ref:`sys-path-init` is allowed to log warnings into
+ stderr. If false (``0``) suppress these warnings. Set to true by default.
+ See also :option:`-X pathconfig_warnings<-X>`.
+
+ .. versionadded:: next
+
.. envvar:: PYTHON_JIT
On builds where experimental just-in-time compilation is available, this
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2026-02-26-21-07-38.gh-issue-145275.qE-3O1.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2026-02-26-21-07-38.gh-issue-145275.qE-3O1.rst
new file mode 100644
index 00000000000000..1723a7c8c10717
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2026-02-26-21-07-38.gh-issue-145275.qE-3O1.rst
@@ -0,0 +1,3 @@
+Added the :option:`-X pathconfig_warnings<-X>` and
+:envvar:`PYTHON_PATHCONFIG_WARNINGS` options, allowing to disable warnings
+from :ref:`sys-path-init`.
diff --git a/Python/initconfig.c b/Python/initconfig.c
index 5ffee9eaf9f550..57629ff8c57380 100644
--- a/Python/initconfig.c
+++ b/Python/initconfig.c
@@ -357,6 +357,9 @@ The following implementation-specific options are
available:\n\
use module globals, which is not concurrent-safe; set to true for\n\
free-threaded builds and false otherwise; also\n\
PYTHON_CONTEXT_AWARE_WARNINGS\n\
+-X pathconfig_warnings=[0|1]: if true (1) then path configuration is allowed\n\
+ to log warnings into stderr; if false (0) suppress these warnings;\n\
+ set to true by default; also PYTHON_PATHCONFIG_WARNINGS\n\
-X tracemalloc[=N]: trace Python memory allocations; N sets a traceback
limit\n \
of N frames (default: 1); also PYTHONTRACEMALLOC=N\n\
-X utf8[=0|1]: enable (1) or disable (0) UTF-8 mode; also PYTHONUTF8\n\
@@ -2350,6 +2353,32 @@ config_init_lazy_imports(PyConfig *config)
return _PyStatus_OK();
}
+static PyStatus
+config_init_pathconfig_warnings(PyConfig *config)
+{
+ const char *env = config_get_env(config, "PYTHON_PATHCONFIG_WARNINGS");
+ if (env) {
+ int enabled;
+ if (_Py_str_to_int(env, &enabled) < 0 || (enabled < 0) || (enabled >
1)) {
+ return _PyStatus_ERR(
+ "PYTHON_PATHCONFIG_WARNINGS=N: N is missing or invalid");
+ }
+ config->pathconfig_warnings = enabled;
+ }
+
+ const wchar_t *xoption = config_get_xoption(config,
L"pathconfig_warnings");
+ if (xoption) {
+ int enabled;
+ const wchar_t *sep = wcschr(xoption, L'=');
+ if (!sep || (config_wstr_to_int(sep + 1, &enabled) < 0) || (enabled <
0) || (enabled > 1)) {
+ return _PyStatus_ERR(
+ "-X pathconfig_warnings=n: n is missing or invalid");
+ }
+ config->pathconfig_warnings = enabled;
+ }
+ return _PyStatus_OK();
+}
+
static PyStatus
config_read_complex_options(PyConfig *config)
{
@@ -2446,6 +2475,11 @@ config_read_complex_options(PyConfig *config)
return status;
}
+ status = config_init_pathconfig_warnings(config);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
+ }
+
return _PyStatus_OK();
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]