58700 Commits
Author SHA1 Message Date
6c695bfad4 gh-160561: Close the duplicated descriptor when socket.fromfd() fails (#160579)
Co-authored-by: wlkr73 <86650480+wlkr73@users.noreply.github.com>
Co-authored-by: lumenyr <86650480+lumenyr@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-10-27 22:56:42 +00:00
Cary Hawkins 926b0bf311 gh-159652: Fix import lock leak when the C stack is nearly exhausted (GH-159660)
When an import failed with a stack overflow RecursionError, releasing the import locks on the error path could itself raise RecursionError, because the cleanup runs in a new C frame. This left the global import lock or a module lock held forever, and later imports in other threads blocked indefinitely.

_imp.acquire_lock() now raises RecursionError when there is not enough stack left to release the lock. importlib calls it before taking any import lock, so this covers the per-module locks too. The module lock weakref callback skips cleanup in that case instead of
reporting an unraisable exception.
2026-10-27 14:43:36 -07:00
Brett Cannon 4521718ca5 GH-160135: Make sure the target triple makes it through configure (GH-160739) 2026-10-27 14:40:17 -07:00
Jelle Zijlstra d9825d504a gh-160279: Keep the venv directory off the import path when running pip (#160282) 2026-10-27 05:02:50 +00:00
Alex Grönholm f4043ab1be gh-160659: Add tests for except* handlers that raise a BaseException (#160660) 2026-10-26 15:18:01 +00:00
Vankudothu Adhi Naik b3683c0ffd gh-160682: Track running function objects in free-threaded GC (#160707) 2026-10-26 20:15:13 +05:30
mpage a9049ee4fb gh-160496: Clear inline values with atomic release stores (#160510) 2026-10-26 19:46:46 +05:30
Gregory P. Smith d9cfd309f2 gh-160513: Call connection_lost() when start_tls() handshake is lost (GH-160514)
SSLProtocol.connection_lost() did not notify the application protocol
while a handshake was in progress, even when start_tls() had handed
over a protocol that had already seen connection_made().  With streams
this left StreamWriter.wait_closed() waiting forever.

ANT-2026-A6ZIAFVT
ANT-2026-4SKWM05E
2026-10-25 16:24:59 -07:00
sobolevn 7b12a415c8 gh-152631: Fix ast.parse on lazy imports with older feature_version (#152632) 2026-10-25 20:35:59 +00:00
tonghuaroot (童话)andStan Ulbrych bb7e16ace9 gh-153605: Fix gettext.GNUTranslations raising struct.error on a malformed .mo file (#153606)
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-10-25 18:06:47 +00:00
Pengyu LeeandStan Ulbrych efbd165392 gh-151947: Fix all Sphinx reference warnings in email.{charset,parser}.rst (#152178)
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-10-25 17:43:56 +00:00
Lysandros Nikolaou aa0e4109a8 gh-153568: Use a managed dict for AST nodes (#160616)
AST nodes had an explicit `__dict__` slot, so every node built by
`ast.parse` allocated its own dict. With `Py_TPFLAGS_MANAGED_DICT`,
node attributes are stored as inline values with shared keys instead.

`ast.parse` is ~15.8% faster, walking trees is ~15.9% faster, and
the memory used by the AST trees is reduced by ~51.6%.
2026-10-25 10:08:26 -07:00
An Long 2468c35c3b gh-150582: Use _winapi for _pyrepl console handles and waits (#150584) 2026-10-25 10:11:43 +00:00
Pengyu Lee ea3a97f245 gh-157354: Honor --with-<name>-sanitizer=no and --without-<name>-sanitizer in configure (#157355) 2026-10-25 09:56:45 +00:00
Gregory P. Smith d59d96853b gh-160300: Reject cookies with a negative version in http.cookiejar (GH-160301)
DefaultCookiePolicy only applied its domain checks to cookies with
version 0 or a positive version.

ANT-2026-TA36I7V7
2026-10-25 07:01:05 +00:00
Gregory P. Smith 9a235416c1 gh-159188: Do not immortalize constants in compile() of an AST (GH-159198)
In the free-threaded build, compile() of a source string sets
suppress_co_const_immortalization so that its output is the same as in
the default build.  The branch for AST objects returned before that, so
constants were replaced by the immortal ones of the interpreter's table
while a tuple of names (such as co_names) which was the same object was
not, and the marshal output depended on the code objects created before
in the process.
2026-10-24 23:59:27 -07:00
Gregory P. Smith ffe13151c0 gh-160520: Apply asyncio ssl_shutdown_timeout after peer EOF (GH-160521)
Keep the SSL shutdown timer running until connection_lost(), and start
it when the peer shuts down first, so that a peer which sends EOF but
does not read cannot keep a closed transport open indefinitely.

ANT-2026-81HUBBJ7
2026-10-24 22:53:46 -07:00
Gregory P. Smith 23a5ba1c93 gh-160549: Fix crash when freeing a busy multi-threaded ZstdCompressor (GH-160550)
ZSTD_freeCCtx() frees a dictionary loaded with ZSTD_CCtx_loadDictionary()
before it stops the worker threads.  Make libzstd wait for unfinished
jobs before freeing the compression context of a ZstdCompressor that
uses worker threads and a ZstdDict.

Works around https://github.com/facebook/zstd/issues/4862
2026-10-24 22:38:04 -07:00
Gregory P. Smith b949033ae8 gh-160535: Keep the ZstdDict alive until the zstd context is freed (GH-160536)
The garbage collector could release a ZstdCompressor's dictionary, or
the digested dictionaries cached by the ZstdDict, while worker threads
of the compression context were still reading them.  They are now only
released on deallocation, after the context has been freed.

ANT-2026-CT3P1CSJ

+ Visit the type in the compressor and decompressor traverse; move NEWS to Library
2026-10-24 22:31:45 -07:00
Gregory P. Smith 7159b152a0 gh-159963: Don't hold parent package import locks while a submodule executes (GH-159965)
Since gh-83065 (3.15.0), the first import of pkg.mod kept pkg's module
lock until pkg/mod.py had finished executing.  Threads that needed only
the finished pkg stayed blocked for that long, and concurrent first
imports could raise _DeadlockError or a spurious "partially initialized
module" ImportError, or hang, with no import cycle involved.

Parent packages are now imported, or waited for if another thread is
initializing them, before the submodule's module lock is taken, so only
that lock is held while the submodule executes.  The lock ordering
deadlock fixed by gh-83065 stays fixed.

importlib.import_module() now returns the partially initialized module
in a circular import split across threads, as the import statement
already did, instead of raising _DeadlockError.  That was long-standing
behavior rather than part of the 3.15.0 regression.
2026-10-24 17:06:37 -07:00
Jelle Zijlstra 656af533dc gh-159739: Keep sqlite3 cursor metadata and factories valid during queries (#160403)
A cursor exposed its description tuple before filling in all the columns, so an allocation failure or a reader on a free-threaded build could encounter an unset tuple entry. An allocation failure could also clear lastrowid and crash the next execute. Build new metadata before replacing the old values and synchronize reads and writes. Keep a strong reference to each row or text factory while it is called so replacing the factory during a fetch cannot destroy an active callable.
2026-10-24 13:46:15 -07:00
Jelle Zijlstra 665bda98e8 gh-159739: Keep text I/O state valid across reentrant callbacks (#160398)
A raw read can reinitialize a TextIOWrapper as write-only, and codec callbacks or finalizers can release an encoder, decoder, or decoded chunk while a read or write still needs it. This can crash the interpreter. Check that a decoder is still available after reading, keep codecs alive across calls, and read the chunk length before transferring ownership. Also recheck StringIO after converting the truncate size because __index__() can close the stream.
2026-10-24 13:45:41 -07:00
tonghuaroot (童话) 0d606d674d gh-153679: Raise ZipImportError for an invalid UTF-8 file name in zipimport (#153680) 2026-10-24 19:20:44 +00:00
An Long 11598362a3 gh-160596: Fix error message in asyncio.proactor_events.sendto() (#160597) 2026-10-24 15:12:39 +00:00
Neil Schemenauer 00c54508c6 gh-159564: Make weakref dereference lock-free. (#159578) 2026-10-24 14:56:31 +00:00
Aslan Osmanov 763fb33915 gh-160239: Remove dead _repr_info() methods from asyncio.windows_events (#160241) 2026-10-24 19:11:15 +05:30
Pieter Eendebak 0dd6a4d417 gh-87613: Use AC vectorcall for weakref.ref() (#159470) 2026-10-24 13:31:45 +00:00
Christian Aurich Zanettini Martins eaab974e8a gh-159244: Fix crash in dict() on a concurrently mutated key/value pair (#159245)
In the free-threaded build, dict() and dict.update() checked that a
list key/value pair had two items and then read them with borrowed
references without holding its lock, so another thread could empty
the list in between and the items were read from a freed or NULL
array.
2026-10-24 20:02:10 +09:00
Liang Hu 457ba33e96 gh-160433: Correct timed log backup names across DST changes (GH-160564) 2026-10-24 07:59:45 +01:00
Christian HeimesandClaude Opus 4.8 7dd8b4736a gh-160040: Distrust compromised eMudhra intermediate CA keys (CVE-2026-115557) (GH-160042)
The ssl module now rejects TLS certificate chains that contain any of a set of
compromised eMudhra intermediate CA keys.  This is an extraordinary measure and
a last line of defense: removing trust is primarily the job of the platform root
store, and the built-in denylist only blocks connections while that update has
not yet reached the OS, a container image, or a bundled trust store in various
Python packages.  Entries are added to the denylist only under a very high
threshold.

The denylist matches on the public key (the SHA-256 digest of the RFC-5280
SubjectPublicKeyInfo), so it also covers the cross-signed certificates that
reuse one of the distrusted keys.

---------

Signed-off-by: Christian Heimes <christian@python.org>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-10-24 05:40:49 +00:00
Jelle Zijlstra c2b7e0a866 gh-159739: Guard cProfile against reentry while processing an external timer (#160405)
An external timer can run Python again when the profiler converts or releases its result or reports an unraisable exception. Calling clear() or disable() at that point could free a profiling context still in use. Calling Profiler.__init__() from the timer could also destroy the active callable. Keep the guard active through result handling and reject reinitialization while an external timer is running.
2026-10-23 21:59:01 -07:00
Pengyu LeeandEmma Smith 95e088ed49 gh-155152: Improve performance of concatenated zstd frames in zipimport (#155154)
Co-authored-by: Emma Smith <emma@emmatyping.dev>
2026-10-23 21:31:41 -07:00
46edd6fa41 gh-89730: Implement support for Encrypted Client Hello (ECH) in ssl (GH-160318)
Co-authored-by: irl <iain@learmonth.me>
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
2026-10-23 20:02:23 -04:00
dec26cefe4 gh-130698: Convert sys.ps1 and sys.ps2 to strings before PyREPL use (#158828)
Co-authored-by: Brett Cannon <brett@python.org>
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-10-23 23:38:52 +00:00
Tian Gao eacae21c12 gh-160125: Support package.module.function for pdb breakpoint command (#160126) 2026-10-23 16:04:40 -07:00
Lysandros Nikolaou 2258026edd gh-160491: Fix location of invalid escapes in f-strings and t-strings (#160493)
Literal parts of f-strings and t-strings are decoded only after the
whole string has been parsed, so a decode error took the location of
the last token. The resulting SyntaxError pointed at the closing quote,
and for multi-line strings it could be on the wrong line.

Raise the error at the literal part being decoded instead.
2026-10-23 15:29:41 -07:00
Zanie Blue 3a440b6569 gh-160388: Load the copied library in the deleted-mapping test (#160396)
The deleted-`libpython` mapping test uses `LD_LIBRARY_PATH` to load a temporary copy of the library. On glibc, an interpreter's `DT_RPATH` can take precedence and load a different copy, so the test fails because the temporary copy was not mapped. Preload the temporary library explicitly so the subprocess maps the file that the test removes. Create the copy beneath the working directory and preload it through a relative path, since `LD_PRELOAD` treats spaces and colons as separators.
2026-10-23 14:52:46 -07:00
Pablo Galindo SalgadoandLysandros Nikolaou b77cb891e9 gh-153568: Skip the expression precedence chain for single-token atoms (#153575)
A bare name or number followed by a token that cannot extend an expression now produces its AST node directly. This avoids the expression precedence chain for common arguments, assignments, and subscripts.

Rules declare the hook with a fastpath flag. The Rule constructor exposes memo and fastpath attributes, and the C generator emits the hook call.

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2026-10-23 14:23:10 -07:00
Davi de Jesus 40c8edd2ca gh-160295: Fix race in test_forkserver_sigkill (GH-160296)
After a SIGKILL, the forkserver can no longer report the first child's
exit status, so proc.join() returns with exit code 255 while the child
may still be running. Wait for the event instead of checking it right
after join().
2026-10-23 21:19:57 +00:00
Christian Aurich Zanettini Martins 2507a7fa73 gh-159294: Fix crash when creating an ExceptionGroup fails with MemoryError (#159295) 2026-10-23 20:57:58 +00:00
Jelle Zijlstra a96fbdca7f gh-159739: Preserve CJK codec state across chunk boundaries and callbacks (#160400)
The HZ encoder can consume a tilde after writing only its first escape byte. A split ISO-2022 escape can exceed the incremental decoder’s pending buffer, and a reset can leave the previous character set selected. Reserve space for both HZ bytes before consuming the tilde, allow the full pending escape, and restore the initial ISO-2022 state on reset. Keep the native codec table and the active encoder error policy alive so replacing their Python owners cannot leave a codec using freed memory.
2026-10-23 13:45:46 -07:00
Pablo Galindo Salgado 612ce88b34 gh-159465: Preserve escape errors in unfinished f-strings and t-strings (#159669) 2026-10-23 13:42:41 -07:00
Cody MaloneyandClaude Opus 5.5 7715c924de gh-158895: Teach libregrtest to output github job summaries (GH-158896)
Goal is to make it faster to triage individual test failures while
keeping the full existing regrtest fidelity. Fairly minimal integration
to hopefully save some human eyeball time.

Setup so only the test summary process should output the summary,
subprocesses have the env var which will cause output unset.

Includes a couple of fixes to existing tests that produced false-positives.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 20:09:50 +00:00
Cody Maloney 53b0004311 gh-154175: Remove time.sleep in test_io daemon test (#157019)
Deterministically get into the deadlock timeout by using mocked Raw I/O
that blocks on threading events. The test still takes quite a bit of
walltime as `_enter_buffered_busy` has a 1 second timeout on a lock
acquisition which this hits.
2026-10-23 13:05:52 -07:00
Petr ViktorinandItamar Oren 18c935f72d gh-157384: Unify _Py_ext_module_loader_info initialization (GH-157758)
- Unify `_Py_ext_module_loader_info_init*` functions. The “core” one was entirely unused, and the difference between “builtin” and “extension” can be expressed in arguments.
- Consolidate getting & checking the module name from spec. (This improves error message wording for `imp.create_builtin` with empty name.)
- Allow non-ASCII names.

Core modules (`sys` and `builtins`) still don't go through the routine.

Co-authored-by: Itamar Oren <itamarost@gmail.com>
2026-10-23 22:01:22 +02:00
Lysandros Nikolaou e548b472f3 gh-153195: Allow splitting the PEG grammar into several files (#159917)
Add an @include meta to pegen: the rules of an included grammar file are
appended to the including file's rules. The C generator emits the rules
of each included file into a separate C file next to the main output.

Use it to move the invalid_* rules from Grammar/python.gram into
Grammar/invalid.gram, which generates Parser/parser_invalid.c.
2026-10-23 12:58:39 -07:00
Pengyu Lee e03def8c23 Fix inaccurate wording in multiple decimal module docstrings (#155688) 2026-10-23 12:54:38 -07:00
Pengyu LeeandStan Ulbrych dc78afeff8 gh-156078: Prevent ZipFile.mkdir() during an active write (#156079)
Fix `ZipFile.mkdir()` so that it raises `ValueError` when another writable
member handle returned by `ZipFile.open(..., mode="w")` is still open.

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-10-23 12:50:21 -07:00
Jelle Zijlstra 0ba58e7e83 gh-159739: Handle pyexpat configuration changes during callbacks (#160399)
A character data callback can disable buffering or remove the next event handler during a flush. Interning an attribute name can also change ordered_attributes while pyexpat is filling the attribute container. Using the freed buffer, cleared handler, or wrong container type can crash the interpreter. Clear the buffered length before dispatch, keep the active handler alive, recheck the buffer and handlers after callbacks, and use one attribute mode for the whole start event.
2026-10-23 12:42:06 -07:00
Zanie BlueandPablo Galindo Salgado 1ff83ad7ad gh-128883: Store ELF perf trampoline templates in read-only data (#160366)
CPython copies the trampoline templates into executable memory. Keep the
ELF source in .rodata so BOLT preserves its bytes and boundaries.

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-10-23 19:29:45 +00:00