716 Commits
Author SHA1 Message Date
Stan Ulbrych c5d09789ea Fix ignored error returns in sys initialization, _ctypes and _interpchannels (#160614) 2026-10-26 14:37:44 +00:00
Arnold DumasandEthan Furman 25b17d4d51 bpo-24053: Add EXIT_SUCCESS and EXIT_FAILURE values in the sys module (GH-14773)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
2026-10-20 10:10:10 -07:00
Brett Cannon 084aff869c GH-158628: Implement sys._wasi_info (GH-159039)
Starting off with WASI version, WASI SDK version, and whether cooperative multithreading is available. All values are required as WASI SDK is the officially  supported compiler according to PEP 11.
2026-10-13 23:53:38 +00:00
Serhiy Storchaka dc590064bd gh-155496: Use Argument Clinic for more functions and methods (GH-158134)
Convert to Argument Clinic:

* builtins dir() and vars()
* property.__set_name__()
* memoryview.__exit__()
* structseq __replace__()
* types.SimpleNamespace.__replace__()
* re.Match.group()
* sys.getsizeof() and sys.set_asyncgen_hooks()
* atexit.register()
* os.scandir() iterator __exit__()
* _dbm, _gdbm and _decimal context manager __exit__()
* _functools lru_cache __copy__() and __deepcopy__()
* _elementtree.SubElement()
* _interpreters.new_config()
* _tkinter call() and wantobjects()
* zoneinfo.ZoneInfo.__init_subclass__()
* internal hamt and stdprinter methods
2026-09-27 19:00:22 +03:00
Victor Stinner a5a4659548 gh-158001: Remove Py_SetProgramName() function (#158024)
Remove Py_SetProgramName(), Py_SetPythonHome(), PySys_SetArgv() and
PySys_SetArgvEx() functions, deprecated since Python 3.11.

Mark the 4 functions as abi_only in stable_abi.toml.
2026-09-24 12:52:54 +02:00
Victor Stinner becfd65c38 gh-158001: Avoid deprecated variable in Py_GETENV() (#158003)
No longer use deprecated Py_IgnoreEnvironmentFlag in Py_GETENV().
Instead, use PyConfig.use_environment when Python is initialized.

Modify also PySys_SetArgv() to use PyConfig.isolated when Python is
initialized.
2026-09-23 17:46:59 +02:00
Hai Zhu 4c9f2675ba gh-157247: Block perf trampoline activation when the main interpreter's JIT is enabled (#157258) 2026-09-11 19:07:26 +05:30
Hood Chatham 05eac890c2 gh-156243: Indicate that emscripten_runtime depends on stringToNewUTF8 (#156335)
Add an explicit declaration an Emscripten dependency on the stringToNewUTF8
library function.
2026-08-26 07:50:13 +10:00
thexai af49df919d gh-152433: Fix errors in sys.getwindowsversion() for UWP build (GH-152604) 2026-08-18 19:55:57 +01:00
k00shi 85c8bcee67 gh-152912: Fix audit hook exception check in sys.addaudithook() (GH-152913) 2026-07-27 19:35:40 +00:00
Petr Viktorin c7b9a13a75 gh-154431: Revert "gh-154431: Fix data race in sys.audithook (#154462)" (GH-154769)
This commit caused a refleak.

This reverts commit 596cd5c5d7.
2026-07-27 16:00:20 +02:00
sobolevn 596cd5c5d7 gh-154431: Fix data race in sys.audithook (#154462) 2026-07-22 14:09:20 +02:00
Victor Stinner 1b41c7b722 gh-152132: Enhance Py_RunMain() and fix bugs (#153461)
* Check for signals more often. Previously, a pending exception could
  be removed by PyErr_Clear().
* Only call _PyInterpreterState_SetNotRunningMain() if
  _PyInterpreterState_SetRunningMain() has been called.
* Add pymain_error() and pyrun_error(): write the error message to
  sys.stderr instead of the C stream stderr.
* Convert _PyPathConfig_UpdateGlobal() PyStatus error to an
  exception.
* Simplify pymain_run_startup(): avoid strerror() which is decoded
  from the wrong encoding. Instead display the exception, Py_fopen()
  raises an OSError with the path object (and can raise other exceptions).
* Add pymain_set_path0() function.
* Add _PySys_FormatV() function.
2026-07-10 01:29:53 +02:00
Victor StinnerandBénédikt Tran b16d23fc9f gh-151218: Replace sys.flags in PyConfig_Set() (#151402)
PyConfig_Set() and sys.set_int_max_str_digits() now replace
sys.flags (create a new object), instead of modifying sys.flags in-place.

Modifying sys.flags in-place can lead to data races when multiple
threads are reading or writing sys.flags in parallel.

Use _Py_atomic functions to get and set max_str_digits members.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-06-16 16:17:33 +00:00
Serhiy Storchaka 287c98f4cb gh-150285: Fix too long docstrings in Argument Clinic code (GH-150338) 2026-05-24 16:16:12 +03:00
Pablo Galindo Salgado 1f3c2679f1 gh-149321: Remove lazy_imports=none startup mode (#149389) 2026-05-19 16:01:15 -07:00
Stan UlbrychandHugo van Kemenade 6a0be131c3 gh-149595: Remove the sys._enablelegacywindowsfsencoding() function (#149596)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-05-12 17:11:34 +01:00
Diego RussoandPablo Galindo Salgado c7b7ca2cd5 GH-126910: Add gdb support for unwinding JIT frames (#146071)
Co-authored-by: Pablo Galindo Salgado <pablogsal@gmail.com>
2026-05-02 13:42:03 +00:00
Gregory P. SmithandClaude Opus 4.6 64afa947f4 gh-146302: make Py_IsInitialized() thread-safe and reflect true init completion (GH-146303)
## Summary

- Move the `runtime->initialized = 1` store from before `site.py` import to the end of `init_interp_main()`, so `Py_IsInitialized()` only returns true after initialization has fully completed
- Access `initialized` and `core_initialized` through new inline accessors using acquire/release atomics, to also protect from data race undefined behavior
- `PySys_AddAuditHook()` now uses the accessor, so with the flag move it correctly skips audit hook invocation during all init phases (matching the documented "after runtime initialization" behavior) ... We could argue that running these earlier would be good even if the intent was never explicitly expressed, but that'd be its own issue.

## Motivation

`Py_IsInitialized()` returned 1 while `Py_InitializeEx()` was still running — specifically, before `site.py` had been imported. See https://github.com/PyO3/pyo3/issues/5900 where a second thread could acquire the GIL and start executing Python with an incomplete `sys.path` because `site.py` hadn't finished.

The flag was also a plain `int` with no atomic operations, making concurrent reads a C-standard data race, though unlikely to manifest.

## Regression test:

The added test properly fails on `main` with `ERROR: Py_IsInitialized() was true during site import`.

---

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 21:54:23 +00:00
Pablo Galindo Salgado ca960b6f38 gh-148110: Resolve lazy import filter names for relative imports (#148111) 2026-04-06 22:29:02 +01:00
Hood Chatham 7dc2f52a6f gh-146197: Include a bit more information in sys._emscripten_info.runtime (#146346) 2026-03-23 21:57:23 +00:00
Gregory P. Smith 4a71946b8f gh-122575: gh-142349: fix sys.flags tuple size (it unintentionally increased) (GH-145988)
the lazy imports PEP initial implementation (3.15 alpha) inadvertently incremented the length of the sys.flags tuple. In a way that did not do anything useful or related to the lazy imports setting (it exposed sys.flags.gil in the tuple). This fixes that to hard code the length to the 3.13 & 3.14 released length of 18 and have our tests and code comments make it clear that we've since stopped making new sys.flags attributes available via sequence index.
2026-03-15 20:30:01 +00:00
Pieter Eendebak 3f7141dac9 gh-145376: Fix refleaks and double decref for code in Python/ (#145666) 2026-03-10 10:46:13 +01:00
Jelle Zijlstra bd13cc09fa gh-145376: Fix various reference leaks (GH-145377) 2026-03-03 16:23:30 +01:00
46d5106cfa gh-142349: Implement PEP 810 - Explicit lazy imports (#142351)
Co-authored-by: T. Wouters <twouters@meta.com >
Co-authored-by: Brittany Reynoso <breynoso@meta.com>
Co-authored-by: Dino Viehland <dinoviehland@meta.com>
2026-02-12 00:15:33 +00:00
Steve Dower a9b6788ae6 gh-144278: Enable overriding sys.implementation's name and cache_tag when building sysmodule.c (GH-144293)
Changing the values requires forking and patching, which is intentional. Simply rebuilding from source does not change the implementation enough to justify changing these values - they would still be `cpython` and compatible with existing `.pyc` files. But people who maintain forks are better served by being able to easily override these values in a place that can be forward-ported reliably.
2026-02-10 00:01:17 +00:00
9fe6e3ed36 gh-142571: Check for errors before calling each syscall in PyUnstable_CopyPerfMapFile() (#142460)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2025-12-11 21:18:52 +00:00
Pablo Galindo Salgado 4ceb077c5c gh-141579: Fix perf_jit backend in sys.activate_stack_trampoline() (#141580) 2025-11-15 02:23:54 +00:00
Bénédikt Tran ae1f435071 gh-111389: replace deprecated occurrences of _PyHASH_* macros (#141236) 2025-11-09 15:14:08 +01:00
Neil Schemenauer c98c5b3449 gh-131253: free-threaded build support for pystats (gh-137189)
Allow the --enable-pystats build option to be used with free-threading.  The
stats are now stored on a per-interpreter basis, rather than process global.
For free-threaded builds, the stats structure is allocated per-thread and
then periodically merged into the per-interpreter stats structure (on thread
exit or when the reporting function is called). Most of the pystats related
code has be moved into the file Python/pystats.c.
2025-11-03 11:36:37 -08:00
sobolevn baf7470515 gh-138886: Remove deprecated PySys_ResetWarnOptions C-API function (#138887) 2025-09-15 12:01:33 +03:00
Petr Viktorin a92aec101e gh-133143: Use _Py_ID for the other literals in sys (GH-138698)
Follow-up refactoring after GH-133143, where we use `_Py_ID` for "big" and "little"
in `abi_info.byteorder`.
This uses `_Py_ID` for `sys.byteorder`, but also `float_repr_style` and a module name.
2025-09-09 14:57:07 +02:00
Adam Turner 5443b9e52f gh-133143: Condense the implementation for `sys.abi_info` (#138672) 2025-09-08 19:21:28 +00:00
1acb718ea2 gh-133143: Add sys.abi_info (GH-137476)
This makes information about the interpreter ABI more accessible.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2025-09-08 14:35:44 +00:00
Adam Turner 918e3ba6c0 GH-137623: Use an AC decorator for docstring line length enforcement (#137690) 2025-08-18 18:29:00 +01:00
Petr ViktorinandJelle Zijlstra 7dfa048bbb gh-135228: Create __dict__ and __weakref__ descriptors for object (GH-136966)
This partially reverts #137047, keeping the tests for GC collectability of the
original class that dataclass adds `__slots__` to.
The reference leaks solved there are instead solved by having the `__dict__` &
`__weakref__` descriptors not tied to (and referencing) their class.

Instead, they're shared between all classes that need them (within
an interpreter).
The `__objclass__` ol the descriptors is set to `object`, since these
descriptors work with *any* object. (The appropriate checks were already
made in the get/set code, so the `__objclass__` check was redundant.)

The repr of these descriptors (and any others whose `__objclass__` is `object`)
now doesn't mention the objclass.

This change required adjustment of introspection code that checks
`__objclass__` to determine an object's “own” (i.e. not inherited) `__dict__`.
Third-party code that does similar introspection of the internals will also
need adjusting.


Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2025-08-18 14:25:51 +02:00
Sam Gross a10152f8fd gh-137400: Fix thread-safety issues when profiling all threads (gh-137518)
There were a few thread-safety issues when profiling or tracing all
threads via PyEval_SetProfileAllThreads or PyEval_SetTraceAllThreads:

* The loop over thread states could crash if a thread exits concurrently
  (in both the free threading and default build)
* The modification of `c_profilefunc` and `c_tracefunc` wasn't
  thread-safe on the free threading build.
2025-08-13 14:15:12 -04:00
6859b95cff gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class collectible (take 2) (GH-137047)
Remove the `__dict__` and `__weakref__` descriptors from the original class when creating a dataclass from it.

An interesting hack, but more localized in scope than gh-135230.

This may be a breaking change if people intentionally keep the original class around
when using `@dataclass(slots=True)`, and then use `__dict__` or `__weakref__` on the
original class.


Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-08-12 13:16:54 +02:00
sobolevnandEric Snow 8ca1e4d846 gh-135645: Added supports_isolated_interpreters to sys.implementation (#135667)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2025-06-21 10:56:14 +03:00
Nadeshiko Manju 1ddfe59320 gh-135543: Emit sys.remote_exec audit event when sys.remote_exec is called (GH-135544) 2025-06-19 21:23:38 +01:00
Serhiy Storchaka bac3fcba5b gh-108512: Add and use new replacements for PySys_GetObject() (GH-111035)
Add functions PySys_GetAttr(), PySys_GetAttrString(),
PySys_GetOptionalAttr() and PySys_GetOptionalAttrString().
2025-05-28 20:11:09 +03:00
Victor Stinner 009e7b3698 gh-134064: Fix sys.remote_exec() error checking (#134067) 2025-05-18 00:24:40 +02:00
Max Bachmann 5d118d0a92 gh-133580: Add missing exception to _sys_getwindowsversion_from_kernel32 (GH-133574) 2025-05-14 14:10:35 +01:00
Serhiy Storchaka c09cec5d69 gh-133886: Fix sys.remote_exec() for non-UTF-8 paths (GH-133887)
It now supports non-ASCII paths in non-UTF-8 locales and
non-UTF-8 paths in UTF-8 locales.
2025-05-13 11:55:24 +03:00
Sergey Miryanov 0ec8fc83a8 gh-133597: Fix memory leak if error occurred in _sys_getwindowsversion_from_kernel32 (GH-133598) 2025-05-08 12:09:20 +01:00
Brandt Bucher b1aa515bd6 GH-133231: Add JIT utilities in sys._jit (GH-133233) 2025-05-05 15:25:22 -07:00
Pablo Galindo Salgado 622176513e gh-132950: Check for Py_SUPPORTS_REMOTE_DEBUG in sys.is_remote_debug_enabled (#132959) 2025-04-25 16:38:48 +00:00
8783cec9b6 gh-129027: Raise DeprecationWarning for sys._clear_type_cache (#129043)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-04-25 15:01:48 +03:00
Neil SchemenauerandKumar Aditya d687900f98 gh-128384: Use a context variable for warnings.catch_warnings (gh-130010)
Make `warnings.catch_warnings()` use a context variable for holding
the warning filtering state if the `sys.flags.context_aware_warnings`
flag is set to true.  This makes using the context manager thread-safe in
multi-threaded programs.

Add the `sys.flags.thread_inherit_context` flag.  If true, starting a new
thread with `threading.Thread` will use a copy of the context
from the caller of `Thread.start()`.

Both these flags are set to true by default for the free-threaded build
and false for the default build.

Move the Python implementation of warnings.py into _py_warnings.py.

Make _contextvars a builtin module.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-04-09 16:18:54 -07:00
943cc1431e gh-131591: Implement PEP 768 (#131937)
Co-authored-by: Ivona Stojanovic <stojanovic.i@hotmail.com>
Co-authored-by: Matt Wozniski <godlygeek@gmail.com>
2025-04-03 16:20:01 +01:00