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>
gh-154307: Fix TemporaryDirectory cleanup on DragonFly BSD (GH-154309)
On DragonFly BSD, removing a file or directory with the UF_NOUNLINK flag
fails with EISDIR (IsADirectoryError) instead of EPERM, so the cleanup did
not reset the flags. Handle IsADirectoryError the same as PermissionError.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gh-154303: Skip test_sqlite3 CLI completion tests on OpenBSD (GH-154304)
OpenBSD's readline does not honor "completion-query-items 0", so completing
many candidates blocks on a "Display all N?" prompt that hangs the
pseudo-terminal opened by run_pty(). Skip the whole Completion class on
OpenBSD, like the existing libedit skip.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gh-154291: Fix socket.has_dualstack_ipv6() on DragonFly BSD (GH-154292)
On DragonFly BSD setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, 0) succeeds without
actually clearing the flag, so has_dualstack_ipv6() wrongly returned True.
Verify with getsockopt() that IPV6_V6ONLY was cleared.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gh-154260: Fix test_flush_parameters on DragonFly BSD (GH-154261)
DragonFly, like FreeBSD, rejects mmap.flush() with MS_ASYNC|MS_INVALIDATE
(EINVAL). Use str.startswith() so the check also matches DragonFly, whose
sys.platform carries a version suffix.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
gh-154258: Fix mmap.resize() crash on NetBSD growing a shared anonymous mapping (GH-154259)
NetBSD mremap() returns a mapping whose grown region is not backed when
growing a shared anonymous mapping, so accessing it crashes. Reject it
with ValueError, as is already done on Linux.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
gh-154176: Fix locale.strxfrm() crash on DragonFly BSD (GH-154177)
Query the result size with a real one-element buffer instead of
wcsxfrm(NULL, s, 0): DragonFly BSD's wcsxfrm() crashes when the
destination is NULL or the size is 0.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
gh-62534: Document that three-argument type() does not call __prepare__ (GH-154028)
The three-argument form of type() skips the metaclass __prepare__
method, which is called by the class statement machinery rather than
by the metaclass call itself. Say so in the type() entry and point to
types.new_class() for dynamic class creation with the appropriate
metaclass, as directed in the issue thread.
gh-139806: Mention pickle error changes in What's New in 3.14 (GH-154020)
The gh-122311 changes made pickle.dump() and pickle.dumps() raise
PicklingError for some failures that previously raised AttributeError,
ImportError, ValueError or UnicodeEncodeError, depending on the
implementation.
Add an entry about this in the "Porting to Python 3.14" section.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>