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).
gh-154525: Skip ncurses find_pair()/alloc_pair() reuse checks before 6.3 (GH-154543)
find_pair() and reuse in alloc_pair() were fixed in ncurses 6.3 (patch 20200411). On earlier versions find_pair() returns -1 and alloc_pair()
allocates a fresh pair instead of reusing an equal one, so
test_dynamic_color_pairs failed on ncurses 6.1 and 6.2.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
John [Wed, 22 Jul 2026 22:43:18 +0000 (23:43 +0100)]
gh-154401: Skip fetching the thread state for non-GC types in `_Py_Dealloc` (GH-154430)
_Py_Dealloc() fetched the current thread state and computed the C
recursion margin on every deallocation, but both are only used by the
trashcan mechanism, which applies only to GC-tracked types. Gate them
behind the Py_TPFLAGS_HAVE_GC check so the common non-GC case (int,
float, str and similar atomic types) skips them.
On platforms where _PyThreadState_GET() reads a _Thread_local via a
function call (e.g. macOS TLV), this removes a call from every non-GC
deallocation.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Create the log file in a fresh directory under a name which has never
been used. On Windows, NTFS file tunneling restored the original
creation time of a file recreated with the same name, which made the
rollover time earlier than the current time and caused an unwanted
rollover.
Also check that the rollover does not happen before the specified time.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gh-154427: Check the access time in UtimeTests only if it is stored (GH-154428)
HAMMER2 on DragonFly BSD does not store the access time and os.stat()
returns the modification time instead. Probe the file system, like it
is already done for the timestamp resolution.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
gh-154419: Find the fish shell in test_venv (GH-154420)
shutil.which('fish') can find the unrelated "Go Fish" game, which is
shipped on several BSD systems. Search PATH for an executable which
behaves like the fish shell instead.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
gh-153291: Fix data race in readline.get_completer() and get_pre_input_hook() (gh-153362)
The setters store these hooks while holding the module critical section
(via set_hook's Py_XSETREF), but the getters read and Py_NewRef the same
fields without it. Annotate both getters with @critical_section, matching
the other readline functions (gh-126895).
Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
gh-153741: Harden IDLE GUI tests for newer Tk and display scaling (#153742)
In test_sidebar.test_mousewheel, only use the X11 <Button-4>/<Button-5> events when testing on
x11 Tk before 8.7. Otherwise, use <Mousewheel> as on other systems.
In test_configdialog, assert the 'disabled' state flag alone instead of
the exact ttk state tuple (which transient pointer states break), and
restore the tests' method masks with addCleanup().
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gh-154366: Fix test_asyncio.test_sendfile timing out on DragonFly BSD (GH-154367)
A 4 KiB receive buffer makes DragonFly defer every window update to the
delayed ACK timer, so each buffer worth of data costs 100 ms. Use a
larger socket buffer there; it is still small enough to pause the
protocol long before all data is sent.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
gh-154352: Fix killing a worker process in regrtest on OpenBSD (GH-154353)
os.getsid() is only allowed for a process in the same session on
OpenBSD. Worker processes are started in their own session, so the
failure means that the process group can be killed.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
gh-154345: Fix test_posix_pty_functions() killing the worker on Solaris (GH-154346)
Pushing the "ptem" STREAMS module makes a session leader without a
controlling terminal acquire the slave as one, so closing the file
descriptors sent SIGHUP to the session and killed the regrtest worker.
Disown it after the pushes, as os.openpty() does.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
gh-154320: Fix swapped __defaults__/__kwdefaults__ in annotationlib docs (#154321)
The bullet list under "Creating a custom callable annotate function"
had the attribute names reversed: positional defaults are __defaults__
(a tuple) and keyword defaults are __kwdefaults__ (a dict). The example
code below was already correct.
gh-139373: Fix asyncio Process.communicate() losing output when cancelled (#154223)
Output already read when communicate() is cancelled (e.g. by a
wait_for() timeout) is now retained on the Process and returned by a
subsequent communicate() call, matching subprocess.Popen.communicate()
behaviour on timeout. Passing input to a communicate() call following a
cancelled one now raises ValueError.
gh-83273: Rewrite csv.Sniffer dialect detection using trial parsing (GH-153694)
Guess the dialect by parsing the sample with every plausible
combination of delimiter, quotechar and escapechar, using the actual
CSV parser in strict mode, and choosing the combination which splits
the sample into rows with the most consistent number of fields. The
old heuristics, which guessed the delimiter from characters adjacent
to quotes and from character frequencies, are removed.
A large sample is parsed incrementally: first only its beginning,
then, after eliminating the combinations which are clearly worse than
the leader, a several times larger part, and so on.
* csv.Sniffer can now detect escapechar='\\'.
* Explicitly requested delimiters are no longer restricted to ASCII.
* A delimiter inside a quoted field no longer wins over the actual
delimiter, and sniffing no longer takes quadratic time on quoted
samples.
* The sample can be cut off at an arbitrary point: in the middle of a
row, of a quoted field or of an escaped sequence.
* Only '\r', '\n' and '\r\n' are treated as row separators, so
characters like '\x1c' can now be detected as a delimiter.
* A preamble (title or comment lines) before the data does not prevent
detection if the data rows outnumber the preamble lines.
* A sample consisting of a single column of quoted fields now raises
csv.Error instead of guessing a delimiter from the content of the
fields, and Sniffer.has_header() no longer raises ValueError for
such samples.
* doublequote is detected by comparing the two readings of the sample.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
gh-103925: Fix csv.Sniffer for a quoted field ending a CRLF line (GH-103926)
"$" does not match before "\r" even in the MULTILINE mode, so such a
field was not found and the delimiter was guessed from character
frequencies instead, which could give a letter.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gh-154308: Clear file flags in os_helper.rmtree() (GH-154310)
On BSD systems a test may leave behind files or directories with flags
such as UF_IMMUTABLE or UF_NOUNLINK set, which prevent the directory from
being modified or removed. Clear the flags before removing, so cleaning
up a temporary directory does not fail.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>