Commit graph

56893 commits

Author SHA1 Message Date
Neko Asakura
e02ac1d907
gh-148515: make optimizer_generator respect multiple caches (#148524) 2026-04-14 12:51:05 +08:00
Russell Keith-Magee
c40e8b016a
gh-148508: Add resilience to SSL preauth tests on iOS (#148536)
Adds handling for a test case seen in the iOS SSL tests where an SSL connection fails to
handshake correctly.
2026-04-14 11:12:37 +08:00
Bénédikt Tran
2662db0c45
gh-148370: prevent quadratic behavior in configparser.ParsingError.combine (#148452) 2026-04-14 00:32:54 +02:00
Bartosz Sławecki
4adffd9efa
gh-144881: Add retry logic to asyncio debugging tools (#148530)
Transient errors can occur when attaching to a process that is actively
using thread delegation (e.g. asyncio.to_thread). Add a retry loop to
_get_awaited_by_tasks for RuntimeError, OSError, UnicodeDecodeError, and
MemoryError, and expose --retries CLI flag on both `ps` and `pstree`
subcommands (default: 3).

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-04-13 22:10:54 +00:00
Joel Dice
a5b76d53bb
gh-146139: Disable socketpair authentication on WASI (#146140)
Calling `connect(2)` on a non-blocking socket on WASI may leave the socket in a
"connecting" but not yet "connected" state.  In the former case, calling
`getpeername(2)` on it will fail, leading to an unhandled exception in Python.

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Brett Cannon <brett@python.org>
2026-04-13 21:06:36 +00:00
Stan Ulbrych
d22922c8a7
gh-148169: Fix webbrowser %action substitution bypass of dash-prefix check (#148170) 2026-04-13 19:02:52 +00:00
Raymond Hettinger
e6893943b7
Minor improvement to statistics.pdf() (gh-148500) 2026-04-13 11:29:15 -05:00
Wulian233
afaf58b573
gh-131798: JIT: Optimize _CHECK_IS_NOT_PY_CALLABLE_EX and _CHECK_IS_NOT_PY_CALLABLE_KW (GH-148494) 2026-04-13 22:41:06 +08:00
Kumar Aditya
88e378cc1c
gh-131798: optimize through keyword and bound method calls in the JIT (GH-148466)
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
2026-04-13 21:14:48 +08:00
Neko Asakura
5e74d920c8
gh-148285: Allow recording uops after specializing uops (GH-148482) 2026-04-13 20:56:29 +08:00
Paweł Szramowski
d24ce178a2
gh-96894: Do not turn echo off for subsequent commands in batch activators (GH-96895) 2026-04-13 11:50:46 +00:00
Jason R. Coombs
480edc1aae
gh-121190: Emit a better error message from importlib.resources.files() when module spec is None" (#148460)
Also merges incidental changes from importlib_resources 7.1.

Co-authored by: Yuichiro Tachibana (Tsuchiya) <t.yic.yt@gmail.com>
2026-04-12 18:15:01 -04:00
Sviataslau
8a398bfbbc
gh-105936: Properly update closure cells for __setattr__ and __delattr__ in frozen dataclasses with slots (GH-144021) 2026-04-12 14:12:19 -07:00
Neko Asakura
63492628be
gh-148438: implement _RECORD_BOUND_METHOD in JIT (GH-148457) 2026-04-13 02:57:55 +08:00
Sacul
18d7d90ef9
gh-131798: Split _CHECK_AND_ALLOCATE_OBJECT into smaller uops (GH-148433)
Co-authored-by: Hai Zhu <haiizhu@outlook.com>
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
2026-04-13 02:31:24 +08:00
Ken Jin
6f7bb297db
gh-146261: JIT: protect against function version changes (#146300)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-04-13 02:23:47 +08:00
Locked-chess-official
1e79bf6c05
gh-139551: add support for BaseExceptionGroup in IDLE (GH-139563)
Meaningfully render ExceptionGroup tracebacks in the IDLE GUI REPL.

---------

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2026-04-12 10:06:41 -07:00
Sam Gross
3ab94d6842
gh-148393: Use atomic ops on _ma_watcher_tag in free threading build (gh-148397)
Fixes data races between dict mutation and watch/unwatch on the same dict.
2026-04-12 10:40:41 -04:00
Wulian233
03d2f035d6
gh-131798: Add _CHECK_IS_NOT_PY_CALLABLE to the JIT optimizer (GH-148434) 2026-04-12 21:07:19 +08:00
Gregory P. Smith
3a7df632c9
gh-146313: Fix multiprocessing ResourceTracker deadlock after os.fork() (GH-146316)
`ResourceTracker.__del__` (added in gh-88887 circa Python 3.12) calls
os.waitpid(pid, 0) which blocks indefinitely if a process created via os.fork()
still holds the tracker pipe's write end. The tracker never sees EOF, never
exits, and the parent hangs at interpreter shutdown.

Fix with two layers:

- **At-fork handler.** An os.register_at_fork(after_in_child=...)
  handler closes the inherited pipe fd in the child unless a preserve
  flag is set. popen_fork.Popen._launch() sets the flag before its
  fork so mp.Process(fork) children keep the fd and reuse the parent's
  tracker (preserving gh-80849). Raw os.fork() children close the fd,
  letting the parent reap promptly.

- **Timeout safety-net.** _stop_locked() gains a wait_timeout
  parameter. When called from `__del__`, it polls with WNOHANG using
  exponential backoff for up to 1 second instead of blocking
  indefinitely. The at-fork handler makes this unreachable in
  well-behaved paths; it remains for abnormal shutdowns.

Co-authored-by: Itamar Oren <itamarost@gmail.com>
2026-04-11 23:06:19 -07:00
CoolCat467
208195dff4
gh-89520: Load extension settings and keybindings from user config (GH-28713)
Extension keybindings defined in ~/.idlerc/config-extensions.cfg were silently ignored because GetExtensionKeys, __GetRawExtensionKeys, and GetExtensionBindings only checked default config. Fix these to check user config as well, and update the extensions config dialog to handle user-only extensions correctly.

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2026-04-12 04:44:33 +00:00
Neil Schemenauer
b216d7b0be
gh-97032: avoid test_squeezer crash on macOS buildbots (gh-115508) (GH-148141)
gh-97032: avoid test_squeezer crash on macOS buildbots (#115508)

avoid test_squeezer crash on macOS buildbots

Co-authored-by: Ned Deily <nad@python.org>
2026-04-11 17:43:04 -07:00
Shamil
235fa7244a
gh-142831: Fix use-after-free in json encoder during re-entrant mutation (gh-142851)
Hold strong references to borrowed items unconditionally (not only in                                                                        
free-threading builds) in _encoder_iterate_mapping_lock_held and                                                                             
_encoder_iterate_fast_seq_lock_held.  User callbacks invoked during                                                                          
encoding can mutate or clear the underlying container, invalidating                                                                          
borrowed references.                                                                                                                         
                                                                                                                                               
The dict iteration path was already fixed by gh-145244.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2026-04-12 00:14:50 +00:00
Artem Yarulin
cef334fd4c
tests: use errno.EBADF instead of hardcoded number in _close_file() (GH-148345)
test_interpreters: use errno.EBADF instead of hardcoded number in _close_file()

Replace the hardcoded `9` check in `Lib/test/test_interpreters/utils.py` with `errno.EBADF`.

Using `errno.EBADF` makes the helper portable across platforms with different errno numbering while preserving the intended behavior.
2026-04-11 17:01:18 -07:00
Ramin Farajpour Cami
8a466fa3d9
gh-145244: Fix use-after-free on borrowed dict key in json encoder (GH-145245)
In encoder_encode_key_value(), key is a borrowed reference from
PyDict_Next(). If the default callback mutates or clears the dict,
key becomes a dangling pointer. The error path then calls
_PyErr_FormatNote("%R", key) on freed memory.

Fix by holding strong references to key and value unconditionally
during encoding, not just in the free-threading build.

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2026-04-11 22:26:36 +00:00
Jason R. Coombs
daa2578dc0
gh-127012: Traversable.read_text now allows/solicits an errors parameter. (#148401)
Applies changes from importlib_resources 6.5.2.
2026-04-11 22:25:20 +00:00
Ramin Farajpour Cami
20994b1809
gh-145105: Fix crash in csv.reader with re-entrant iterator (GH-145106)
When a custom iterator calls next() on the same csv.reader from
within __next__, the inner iteration sets self->fields to NULL.
The outer iteration then crashes in parse_save_field() by passing
NULL to PyList_Append.

Add a guard after PyIter_Next() to detect that fields was set to
NULL by a re-entrant call, and raise csv.Error instead of crashing.
2026-04-11 15:18:02 -07:00
Ramin Farajpour Cami
c29d75610b
gh-145200: Fix EVP_MAC_CTX leak in hashlib HMAC on init failure (GH-145201)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-04-11 15:10:43 -07:00
Gregory P. Smith
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
Shixian Li
6e2272d0b1
gh-94523: IDLE: Detect file if modified and prompt the user to refresh (GH-145625) 2026-04-11 14:36:59 -07:00
Daniel Hollas
dd2735d177
gh-137855: Improve import time of dataclasses by lazy importing re and copy modules (#148379)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-04-11 21:05:24 +00:00
Wulian233
a059e85866
gh-131798: Add _IS_NONE to the JIT optimizer (GH-148369) 2026-04-11 23:02:46 +08:00
Pieter Eendebak
1c89817f51
gh-148276: Optimize object creation and method calls in the JIT by resolving __init__ at trace optimization time (GH-148277)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
2026-04-11 22:22:42 +08:00
Neko Asakura
9831dea3bf
gh-148211: decompose _POP_TWO/_POP_CALL(_ONE/_TWO) in JIT (GH-148377) 2026-04-11 20:46:56 +08:00
Neko Asakura
72006a71b2
gh-148211: decompose [_POP_TWO/_INSERT_2]_LOAD_CONST_INLINE_BORROW in JIT (GH-148357) 2026-04-11 18:27:51 +08:00
Kumar Aditya
8f17140fc1
gh-131798: split _CALL_BUILTIN_CLASS to smaller uops (#148094) 2026-04-10 17:28:20 +00:00
Seth Larson
05ed7ce7ae
gh-146211: Reject CR/LF in HTTP tunnel request headers (#146212)
Co-authored-by: Illia Volochii <illia.volochii@gmail.com>
2026-04-10 15:21:42 +00:00
Ken Jin
266247c9a6
gh-148171: Convert CALL_BUILTIN_FAST to leave inputs on the stack for refcount elimination in JIT (GH-148172) 2026-04-10 23:11:18 +08:00
Neko Asakura
aea0b91d65
gh-148211: decompose [_POP_CALL_X/_SHUFFLE_2]_LOAD_CONST_INLINE_BORROW in JIT (GH-148313) 2026-04-10 21:57:01 +08:00
Stefan Zetzsche
1a0edb1fa8
gh-145831: email.quoprimime: decode() leaves stray \r when eol='\r\n' (#145832)
decoded[:-1] only strips one character, leaving a stray \r when eol
is two characters. Fix: decoded[:-len(eol)].
2026-04-09 16:21:49 -04:00
Neko Asakura
0f49232664
gh-148211: decompose _INSERT_1_LOAD_CONST_INLINE(_BORROW) in JIT (GH-148283) 2026-04-10 00:45:39 +08:00
gaweng
d8c5658156
gh-148254: Use singular "sec" in timeit verbose output (#148290) 2026-04-09 17:37:19 +03:00
Sacul
38d3aef375
gh-134584 : Optimize and eliminate redundant ref-counting for MAKE_FUNCTION in the JIT (GH-144963) 2026-04-09 22:22:53 +08:00
Victor Stinner
b7e1d51e6b
gh-148241: Fix json serialization for str subclasses (#148249)
Fix json serialization: no longer call str(obj) on str subclasses.

Replace PyUnicodeWriter_WriteStr() with PyUnicodeWriter_WriteASCII()
and private _PyUnicodeWriter_WriteStr().
2026-04-09 13:50:44 +02:00
Kumar Aditya
458aca9237
gh-131798: fold super method lookups in JIT (#148231) 2026-04-09 13:25:01 +05:30
Pablo Galindo Salgado
efde4333bf
gh-148225: Validate profiling.sampling replay input (#148243) 2026-04-08 23:34:46 +00:00
Pablo Galindo Salgado
09968dd2a9
gh-148105: _pyrepl: switch console refresh to structured rendered screens (#146584) 2026-04-08 23:42:26 +01:00
nmartensen
442f83a5ea
gh-70039: smtplib: store the server name in ._host in .connect() (#115259)
Original patch by gigaplastik, extended with a few more tests.

Addresses gh-70039 and bpo-25852: failure of starttls if connect is called explicitly.
2026-04-08 17:46:25 -04:00
Kumar Aditya
6e081614eb
gh-148210: fix incorrect _BINARY_OP_SUBSCR_DICT JIT optimization (GH-148213) 2026-04-08 23:23:20 +08:00
Sacul
bb03c8bd02
gh-145866: Convert _CALL_METHOD_DESCRIPTOR_NOARGS to leave its inputs on the stack to be cleaned up by _POP_TOP (GH-148227) 2026-04-08 23:21:37 +08:00