gh-154863: Fix iconv encoding of ISO-2022-CN-EXT returning empty bytes (GH-154899)
The flush that emits the pending shift sequence can report a nonreversible
conversion, which the loop mistook for a substituted character. It then
retried while still flushing, converted nothing and returned the empty
output buffer.
gh-154848: Enforce frame boundaries in the C unpickler (GH-154893)
The C unpickler did not enforce PEP 3154 frame boundaries: an opcode or its
argument could straddle a frame, and a new frame could begin before the
previous one ended. Such reads now raise UnpicklingError, as in the pure
Python implementation.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Peter Hawkins [Fri, 31 Jul 2026 01:28:20 +0000 (18:28 -0700)]
gh-152075: Avoid lock contention in _Py_Specialize_LoadGlobal under free threading (gh-153720)
Under high thread concurrency in free-threaded builds, `_Py_Specialize_LoadGlobal` suffers from lock contention when acquiring the critical section mutexes for the `globals` and `builtins` dictionaries during bytecode specialization.
This PR skips LOAD_GLOBAL bytecode specialization if acquiring the two object mutexes would block.
gh-154874: Fix the sign of curses.termattrs() (GH-154875)
termattrs() returns a chtype mask, but it was routed through an int, so a
terminal that advertises A_ITALIC came back negative and the result could
no longer be passed to the attribute functions.
GH-148468: Accept string-like proxy objects in colorized argparse help (#154653)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
* Ported existing tests to cover both the CommandCompiler and Compile classes
* Added tests that cover the case when PyCF_ONLY_AST is set
* Added tests that cover the case when the compile method returns a code object with flags
Wenzel Jakob [Thu, 30 Jul 2026 12:00:08 +0000 (14:00 +0200)]
gh-151728: Clear the typing caches at interpreter shutdown (GH-154858)
The typing module caches every subscripted type. When an extension module
leaks a reference to typing, these caches also keep types owned by other
(correct) extension modules alive past interpreter shutdown, where nothing
can free them anymore. The cache_clear callables are already collected in
typing._cleanups, so registering them with atexit is enough to avoid this.
Malcolm Smith [Thu, 30 Jul 2026 02:31:40 +0000 (03:31 +0100)]
Minor fixes for Android (#154895)
A collection of small cleanups for Android support:
* Clarifies the documentation around version number handling for iOS and
Android in os.uname and platform.release
* Ensures that automated NDK installs surface messages written to stderr
* Makes the Android NDK check more robust for incomplete downloads
* Corrects some linting errors in Android build scripts
gh-135736: Fix interaction between TaskGroup and aclose() (#154649)
Currently if you have a generator like:
```
async def test():
async with asyncio.TaskGroup() as tg:
async for x in whatever():
yield x
```
If aclose() is called on the generator and GeneratorExit is raised,
the TaskGroup's __aexit__ will raise a BaseExceptionGroup, and that
will be raised from the aclose() call instead of it being swallowed.
Fix this by raising GeneratorExit from __aexit__ when:
1. The body of task group raised it
2. No subtasks raised exceptions
This makes GeneratorExit work without swallowing other exceptions
(like it would if we just added it to _is_base_error).
gh-154836: Fix Popen.wait() with very large timeouts on the pidfd/kqueue wait paths (GH-154837)
The event-driven wait introduced by gh-83069 passes the caller's timeout
unclamped to poll() / kqueue.control(), so values that do not fit the C
timestamp conversion (float('inf'), sys.maxsize, 1e10, ...) raise
OverflowError on Linux and, on macOS/BSD, a misleading
"TypeError: timeout must be a real number or None" -- all of which
worked on 3.14 and earlier.
- Lib/subprocess.py: clamp each wait to _MAXIMUM_WAIT_TIMEOUT (24h,
following asyncio's MAXIMUM_SELECT_TIMEOUT precedent) and loop until
the real deadline in both _wait_pidfd() and _wait_kqueue().
- Modules/selectmodule.c: only rewrite the kqueue.control() timeout
conversion failure into TypeError when the original exception IS a
TypeError, exactly like the select()/poll()/devpoll()/epoll() sites,
so OverflowError surfaces for out-of-range values.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
gh-131565: Implement ctypes.util.dllist() in the _ctypes extension (GH-154255)
On NetBSD dl_iterate_phdr() reports only the link-map group of the calling
object. Called through ctypes, the caller is libffi's closure trampoline,
which belongs to no object, so only the main executable was reported.
Calling dl_iterate_phdr() from the _ctypes extension module makes _ctypes
the caller and reports all loaded shared libraries.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
gh-64192: Add *buffersize* to `imap()`/`imap_unordered()` in `multiprocessing.pool` (GH-136871)
The new argument allows consuming the input iterator lazily, potentially
saving memory, and allowing long/infinite iterators.
It mirrors the *buffersize* argument to `concurrent.futures.Executor.map`
that was added in 3.14.
Co-authored-by: Oleksandr Baltian <oleksandr.baltian@maklai.com.ua> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Sasha Baltian <sasha.baltian@hyperexponential.com>
gh-154781: Fix garbage from curses window.in_wstr() (GH-154782)
in_wstr() searched the result for a terminating null, but winnwstr()
writes one only if it stored at least one character. Use the number of
characters it returns as the length.
gh-154788: Make curses window.getparent() unconditional (GH-154789)
getparent() calls no curses function, it returns the window's stored parent,
but it was compiled only when the ncurses extension functions were present.
Close the guard after getscrreg(), which does need it.
The test moves out of test_state_getters, which is gated on is_scrollok(), so
that getparent() is covered on backends without the extensions.
gh-154271: Enable socket ancillary data and forkserver on illumos (GH-154273)
illumos declares the socket ancillary-data API (CMSG_*, sendmsg(),
recvmsg()) only under _XOPEN_SOURCE >= 600. __EXTENSIONS__ keeps the
other platform features. This enables the forkserver start method.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gh-154324: Fix os.sendfile() error reporting on illumos (GH-154327)
illumos sendfile(3EXT) returns the number of transferred bytes by adding
it to the offset without initializing it, so the offset cannot be used to
detect a partial write. Use sendfilev(3EXT), which reports the number of
transferred bytes in an explicit out parameter.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Put common information in an intro section at the beginning, rather
than in a duplicate doc entry for `SequenceMatcher`
- Merge the two doc entries for `Differ`
- Document timing as a CPython implementation detail
- Group examples together
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
gh-154786: Fix crashes on a screen without a terminal (GH-154787)
screen.use() makes its screen current for the callback, so a new_prescr()
screen, which has no terminal, can be current without set_term().
Operations that need a terminal then crashed inside curses.
Raise curses.error instead, checking that stdscr exists.
Dan Shernicoff [Tue, 28 Jul 2026 01:41:17 +0000 (21:41 -0400)]
gh-154746: Update docstring for `collections.Counter` (GH-154792)
Added a note to `collections.Counter`'s docstring that initializing a `Counter` from a `Mapping` or `Counter` will have different behaviour than initializing from other `Iterable`s.
This behaviour was already documented in the canonical docs but is missing from the help() output.
gh-154467: Fix empty (Pdb) prompt when attaching to a process with pdb -p (#154469)
_PdbServer inherits _cmdloop, which wraps cmdloop() in
_maybe_use_pyrepl_as_stdin(). That context manager blanks self.prompt to ''
so that a local pyrepl draws the prompt itself. The remote server, however,
never reads from a local pyrepl -- it transmits self.prompt to the client
over the socket -- so the blanking made it send an empty prompt whenever the
target process had a pyrepl-capable terminal (pyrepl_input is set).
Override _maybe_use_pyrepl_as_stdin() in _PdbServer to a no-op, keeping the
real prompt. Add an integration test that attaches to a target running under
a pty, so PyREPL is genuinely enabled inside it, and asserts the transmitted
prompt is "(Pdb) ".
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gh-152548: Add a test.support.isolation.runInSubprocess() decorator (GH-152551)
Run a test in a fresh interpreter subprocess, so that it does not share global
or interpreter state with the rest of the test run. It can decorate a test
method (only that method runs in a subprocess) or a TestCase subclass (the
whole class runs in one subprocess, with its setUpClass()/setUp()/tearDown()/
tearDownClass() running there rather than in the parent).
Failures, errors and skips, including those of individual subtests, are
reported for the test; a failure or an error shows the original subprocess
traceback. The subprocess inherits the parent's resource, memory, verbosity
and failfast configuration, so that requires_resource(), bigmemtest() and
similar behave the same in both processes. A decorated test is skipped where
subprocesses are unavailable, since it must spawn one.
The test.support.isolation.runningInSubprocess flag is true in the subprocess,
so that fixtures can choose what to run there.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
gh-154751: Fix use-after-free in curses.initscr() after newterm() (GH-154752)
initscr() called while a newterm() screen is current returned a second
window object over that screen's standard window, with no reference to
the screen. Either wrapper could then free the window used by the other.
gh-154744: Improve detection of skipinitialspace in csv.Sniffer (GH-154745)
Detect the padding by parsing the sample both with and without
skipinitialspace and comparing the two readings, instead of testing
whether every field following a delimiter starts with a space.
gh-122931: Allow stable abi3 API extensions to include a multiarch tuple in the filename (GH-152461)
This permits stable ABI extensions for multiple architectures to be
co-installed into the same directory, without clashing with each other,
the same way (non-stable ABI) regular extensions can.
It is listed before the current platform-less suffixes since it's more
specific.
The platform is stored in a new pyconfig.h define & sysconfig
variable, SOABI_PLATFORM.
On some known architectures (FreeBSD, Windows), this
will be undefined/zero; these won't have the new tag (yet).
Add SOABI_PLATFORM & ALT_SOABI the info to
`make pythoninfo` as well.
Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
gh-154070: Build the curses module wide by capability, not by name (GH-154071)
configure built the module wide (HAVE_NCURSESW) only for a backend named
ncursesw. Probe for the wide API in the ncurses and auto backends too, so
a widec-built ncurses keeping the plain name (pkgsrc, macOS) is built wide.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
gh-93251: Decode localized socket error messages from the locale encoding (GH-154683)
The gai_strerror() and hstrerror() messages were decoded as UTF-8, so
gaierror and herror could be replaced with UnicodeDecodeError if the
message is localized and the locale encoding is not UTF-8.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
gh-153862: Fix spurious color pair in curses window.inch() on a wide build (GH-154703)
winch() returns the whole code point, so inch() replacing only its low
8 bits left the high bits in the color field. Rebuild from
getcchar()'s attributes and color pair.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
GH-142035: Fix wrapping of colorized argparse help text (#154634)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
gh-70990: Support bytes addresses of Unix sockets in SysLogHandler (GH-154500)
Only a str address was recognized as a Unix domain socket. A bytes
address, which socket.bind() accepts, fell through to the (host, port)
branch and raised ValueError.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gh-154580: Fix python-gdb.py pretty-printing non-ASCII strings in non-UTF-8 locales (GH-154581)
The gdb pretty-printer used locale.getpreferredencoding() to decide whether to
escape a character, but gdb writes its output in its host charset. Use
gdb.host_charset() instead. test_strings had the same problem.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Steve Stagg [Fri, 24 Jul 2026 15:25:11 +0000 (16:25 +0100)]
gh-153419: Fix several issues around bytearray __init__ (#153498)
Introduce a bytearray_new() function to ensure that
ob_bytes_object is always set on a bytearray.
Resizing a bytearray to 0 length now explicitly sets
the ob_bytes_object to the empty constant immortal.
Add a check in the 'bytearray init from string'
fast path to ensure there are no active exports.
This fixes asserts/crashes on the following:
- bytearray(1).__init__()
- bytearray().__new__(bytearray).append(1)
- a = bytearray(); b = memoryview(a); a.__init__('x', 'ascii')
gh-76595: Add tests for PyCapsule_Import() (GH-154588)
Add _testcapi helpers to create a capsule with an arbitrary name and to call PyCapsule_Import(), and Python tests covering the current behavior: only the first component of the dotted name is imported, the rest are attribute lookups.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
gh-73458: Fix logging.config.listen() on a host without an IPv4 address (GH-154491)
The server is created in a thread which set the "ready" event only after a
successful start, so a failure to start left the caller waiting for that
event forever. Set it also on failure.
The receiver always used AF_INET, which fails if the host has no IPv4
address, for example if "localhost" is only aliased to ::1. Use the family
of the first resolved address in such case.
Also fixes gh-82076.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gh-153570: Fix use-after-free in bytearray.take_bytes() with a reentrant __index__ (#153572)
bytearray.take_bytes() cached the size before the argument's __index__ call and
used it for the bounds check and the buffer reads, so an __index__ that resizes
the bytearray left it reading freed memory. Re-read the size after __index__,
matching bytearray.__setitem__ (GH-91153).