Do not mention `__annotations__` dictionaries, as this is slightly
outdated since 3.14.
Rewrite the note about possible exceptions for clarity. Also do not
mention imported type aliases, as since 3.12 aliases with the `type`
statement do not suffer from this limitation anymore.
(cherry picked from commit 8bf99ae3a9)
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
The documentation previously stated that Concatenate is only valid
when used as the first argument to Callable, but according to PEP 612,
it can also be used when instantiating user-defined generic classes
with ParamSpec parameters.
(cherry picked from commit 75ff1afcb6)
Co-authored-by: John Seong <39040639+sandole@users.noreply.github.com>
_PyRawMutex_UnlockSlow CAS-removes the waiter from the list and then
calls _PySemaphore_Wakeup, with no handshake. If _PySemaphore_Wait
returns Py_PARK_INTR, the waiter can destroy its stack-allocated
semaphore before the unlocker's Wakeup runs, causing a fatal error from
ReleaseSemaphore / sem_post.
Loop in _PyRawMutex_LockSlow until _PySemaphore_Wait returns Py_PARK_OK,
which is only signalled when a matching Wakeup has been observed.
Also include GetLastError() and the handle in the Windows fatal messages
in _PySemaphore_Init, _PySemaphore_Wait, and _PySemaphore_Wakeup to make
similar races easier to diagnose in the future.
(cherry picked from commit ad3c5b7958)
gh-146578: _zstd: Fix printf format for pledged size errors (GH-146576)
Use %llu instead of %ull for unsigned long long in zstd_contentsize_converter ValueError messages.
(cherry picked from commit 09233bd198)
Co-authored-by: cui <cuiweixie@gmail.com>
Correct the description of the default state of test module compilation.
(cherry picked from commit d206d42834)
Co-authored-by: Stan Ulbrych <stan@python.org>
gh-148763: Fix paramter name in `multiprocessing.connection.send_bytes/recv_bytes_into` docs (GH-126603)
(cherry picked from commit e50acef0b2)
Doc: Fix buf argument name in multiprocessing connection send_bytes
Co-authored-by: Matthew Davis <7035647+mdavis-xyz@users.noreply.github.com>
Forbid marshalling recursive code and slice objects which
cannot be correctly unmarshalled.
Add multiple tests for recursive data structures.
(cherry picked from commit 2e37d83641)
gh-148651: Fix refcount leak in _zstd decompressor options (GH-148657)
The option parsing in Modules/_zstd/decompressor.c had a missing Py_DECREF(value) before the early return -1 when PyLong_AsInt(key) fails. The identical code in Modules/_zstd/compressor.c line 158 has the fix.
(cherry picked from commit 446edda209)
Co-authored-by: Michael Bommarito <michael.bommarito@gmail.com>
gh-148535: Don't use gcc -fprofile-update=atomic flag on i686 (GH-148554)
The -fprofile-update=atomic flag was added to fix a random GCC
internal error on PGO build (gh-145801) caused by corruption of
profile data (.gcda files). The problem is that it makes the PGO
build way slower (up to 47x slower) on i686. Since the GCC internal
error was not seen on i686 so far, don't use -fprofile-update=atomic
on i686.
(cherry picked from commit 2faceeec5c)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-137814: [3.14] Fix __qualname__ of __annotate__ functions in the interpreter
I'd still like to do #137842 on 3.15+, but that requires changing bytecode and we can't
really afford to do that in 3.14. So to fix this in 3.14, let's patch things up in the
ceval loop instead.
This is safe because the compiler only sets __annotate__ to just-created dedicated
annotate functions.
tiny edit, fix a couple of minor typos in enum and sqlite3 docs (GH-148580)
pair of minor doc typo fixes
(cherry picked from commit 236aa0a4e2)
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
gh-137335: remove a mktemp use in multiprocessing.connection to avoid security scanner noise (GH-148578)
remove a mktemp use to avoid security scanner noise
(cherry picked from commit fd81246bd5)
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
The Generator._make_boundary regex did not match on boundary phrases correctly when using CRLF line endings due to re.MULTILINE not considering \r\n as a line ending.
(cherry picked from commit 4af46b4ab5)
Co-authored-by: Henry Jones <44321887+henryivesjones@users.noreply.github.com>
Adds handling for a test case seen in the iOS SSL tests where an SSL connection fails to
handshake correctly.
(cherry picked from commit c40e8b016a)
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
gh-146139: Disable `socketpair` authentication on WASI (GH-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.
(cherry picked from commit a5b76d53bb)
Co-authored-by: Joel Dice <joel.dice@akamai.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Brett Cannon <brett@python.org>
The watcher-bits read in _PyDict_NotifyEvent needs to use acquire to
synchronize with the release from PyDict_Watch so that the callback
publication is visible before the callback is invoked.
(cherry picked from commit 19f96f99fe)
Co-authored-by: Sam Gross <colesbury@gmail.com>
gh-148395: Fix a possible UAF in `{LZMA,BZ2,_Zlib}Decompressor` (GH-148396)
Fix dangling input pointer after `MemoryError` in _lzma/_bz2/_ZlibDecompressor.decompress
(cherry picked from commit 8fc66aef6d)
Co-authored-by: Stan Ulbrych <stan@python.org>
Ensures that the testbed's Gradle configuration uses the cross-build environment
variable, and that variable is passed to Gradle by the cross-build script.
(cherry picked from commit b29afe62f7)
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
Co-authored-by: Malcolm Smith <smith@chaquo.com>
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.
(cherry picked from commit cef334fd4c)
Co-authored-by: Artem Yarulin <artem.yarulin@kapteko.com>
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.
(cherry picked from commit 3a7df632c9)
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Itamar Oren <itamarost@gmail.com>
Fixes data races between dict mutation and watch/unwatch on the same dict.
(cherry picked from commit 3ab94d6842)
Co-authored-by: Sam Gross <colesbury@gmail.com>
gh-147965: Add shutdown() to multiprocessing.Queue excluded methods (GH-147970)
The multiprocessing.Queue documentation states it implements all
methods of queue.Queue except task_done() and join(). Since
queue.Queue.shutdown() was added in Python 3.13,
multiprocessing.Queue also does not implement it. Update the docs
to include shutdown() in the list of excluded methods.
(cherry picked from commit 22290ed011)
Co-authored-by: WYSIATI <chester.lee.cold@gmail.com>
gh-148337: Document `importlib.resources` security model (GH-148340)
(cherry picked from commit 70b86e7829)
Co-authored-by: Stan Ulbrych <stan@python.org>