[3.15] gh-85943: Fix BytesWarning in the struct format cache under -bb (GH-153627) (GH-153834)
Normalize bytes format strings to str before using them as the cache key,
so that equal str and bytes formats no longer collide and get compared.
(cherry picked from commit 190d2ffbb969ad571fd12d4988b37519091194d5)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
[3.15] gh-151644: Fix data race in sys.setdlopenflags/getdlopenflags under free-threading (gh-151768) (#153790)
gh-151644: Fix data race in sys.setdlopenflags/getdlopenflags under free-threading (gh-151768)
In free-threading builds, concurrent calls to sys.getdlopenflags() and
sys.setdlopenflags() race on interp->imports.dlopenflags. Fix by
using FT_ATOMIC_LOAD_INT_RELAXED / FT_ATOMIC_STORE_INT_RELAXED in
_PyImport_GetDLOpenFlags and _PyImport_SetDLOpenFlags, consistent with
how analogous interpreter-state integer fields (lazy_imports_mode,
pystats_enabled) are protected.
Relaxed ordering is correct here: dlopenflags is a standalone config
integer with no ordering relationship to other memory.
(cherry picked from commit cde31ec135905472f1137dddcc8227af2430d89c)
Co-authored-by: Jiucheng(Oliver) <git.jiucheng@gmail.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
[3.15] gh-153550: Modernize the older prose sections of the tkinter documentation (GH-153647) (GH-153773)
Refresh the narrative "Tkinter life preserver" and "Handy reference"
sections to match the overhauled reference (gh-86726 and gh-153549).
* Rework "The packer" into a general "Geometry management" section
covering grid, pack and place, and cross-link it with the Grid, Pack
and Place reference classes.
* Rework "The window manager" and "Coupling widget variables", replacing
the dated App(Frame) examples with direct Tk() and ttk examples.
* Replace page-number citations to Ousterhout's book with links to the
relevant Tk man pages.
* Modernize the tkinter.ttk front matter and its Tcl/Tk links, and add
cross-references between the two documents.
* Reconcile the "Packer options" and "Tk option data types" lists with
the reference, and fill in the empty Entry index list.
* Fix the malformed target-selection list in tkinter.dnd.
(cherry picked from commit 93beea7e5a3c5a03253e6812a06f2497505aeb30)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Separate tests for module-level API and for the MimeTypes class.
* Add tests for mimetypes.init() and MimeTypes() with knownfiles and with
explicitly passed files.
Compute probe coordinates from each widget's own realized geometry
instead of hardcoding pixels such as (5, 5) or width - 5, which land on
a different element, or miss it entirely, at a high display scaling.
(cherry picked from commit 87411d0742f070b1424c08b41cf3af49d377b215)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
[3.15] gh-153631: Move to `macos-26` runner for iOS (GH-153632) (#153673)
Switches iOS CI to use the macos-26 runner, and makes a small change to the iOS
build script to improve build stability. xcodebuild doesn't guarantee that the
CoreSimulatorService is running before starting a simulator. If the service
isn't running, xcodebuild reports that no simulators are available, and fails to
start the test app. However, simctl blocks until the simulator is available, and
simctl is used to evaluate the default simulator. So - the iOS build script now
unconditionally determines the default simulator, even if a specific simulator
is requested.
(cherry picked from commit 2dc1a91af801ea896e21f6c6e6cc41f57e8268d9)
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
[3.15] gh-152405: Do not expose the internal mapping when rich-comparing `MappingProxyType` objects (GH-152483) (#153670)
gh-152405: Do not expose the internal mapping when rich-comparing `MappingProxyType` objects (GH-152483)
(cherry picked from commit 701a7c5408f689b26c46ed7ed13879375fa82959)
[3.15] gh-153037: Make ZstdFile.__next__ raise io.UnsupportedOperation on non-readable files (GH-153045) (#153638)
gh-153037: Make ZstdFile.__next__ raise io.UnsupportedOperation on non-readable files (GH-153045)
Make `ZstdFile.__next__` raise `io.UnsupportedOperation` on non-readable files, consistent with other compression modules.
(cherry picked from commit ed716551e13d1e46a5cd17955657d64b8824626a)
[3.15] gh-90431: Document cancellation behavior of asyncio.wait() and asyncio.as_completed() (GH-153616) (#153617)
gh-90431: Document cancellation behavior of asyncio.wait() and asyncio.as_completed() (GH-153616)
(cherry picked from commit dd2faeb33d5fa0d2635b91ece6eaebd34c61408c)
[3.15] gh-151292: Change `total_samples:u32` in the binary format to `total_samples:u64` (GH-153425) (#153436)
gh-151292: Change `total_samples:u32` in the binary format to `total_samples:u64` (GH-153425)
(cherry picked from commit 1d196507e6496aab072e741e03d3565142a681ae)
[3.15] gh-152614: Add raises to `QueueShutDown` in `asyncio.Queue.put_no_wait` and `asyncio.Queue.get_nowait` documentation methods (GH-152681) (#153565)
gh-152614: Add raises to `QueueShutDown` in `asyncio.Queue.put_no_wait` and `asyncio.Queue.get_nowait` documentation methods (GH-152681)
(cherry picked from commit d1a5b54abaca2b443c7642ef3a7be8e1cd077ae3)
[3.15] gh-126877: Fix the configure check for Tcl/Tk with optimizing compilers (GH-153543) (GH-153553)
The check assigned the addresses of Tcl_Init() and Tk_Init() to unused
variables, which optimizing compilers can eliminate, so it linked even
when the libraries were missing. Call the functions instead.
(cherry picked from commit ff0a9ae269fa38c21f01bdea1a7ff5d439c4f681)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
[3.15] gh-86726: Fix and improve tkinter documentation and docstrings (GH-153549) (GH-153551)
Correct inaccurate return-type and option descriptions in the tkinter
reference, and add missing module and class docstrings.
(cherry picked from commit 77cb7560c07feed0d5b144c0c1735e1620c96f51)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
[3.15] gh-153333: Read tkinter profile scripts with the source file's encoding (GH-153334) (GH-153541)
Tk.readprofile ran the user's ~/.CLASS.py and ~/.BASE.py scripts with
exec(open(path).read()), decoding them with the locale encoding. Read
them in binary mode so exec() honors each script's own coding cookie.
(cherry picked from commit bac73b0f4ea475cbfb11f41579129c9d07075c34)
[3.15] gh-153062: Fix a crash iterating itertools.tee on the free-threaded build (gh-153063) (gh-153475)
itertools.tee branches share a linked list of teedataobject cells. On the free-threaded build, iterating one branch from multiple threads, or iterating sibling branches concurrently, raced on the shared cells and each branch's position, corrupting refcounts and crashing.
Lock each teedataobject while reading, extending, or clearing it, and snapshot each branch's position under the tee object's own lock, revalidating before advancing, so the two locks are never nested. Concurrent iteration of one tee is undefined and may raise RuntimeError as documented, but no longer crashes.
The free-threading snapshot and revalidation add per-element overhead on the default build, where the GIL already serializes access. Guard that path under Py_GIL_DISABLED so the default build keeps the original iteration and the free-threaded path is unchanged.
Victor Stinner [Fri, 10 Jul 2026 15:18:14 +0000 (17:18 +0200)]
[3.15] gh-152785: Upgrade Ubuntu from 24.04 to 26.04 in GitHub Actions (#152717) (#153416)
gh-152785: Upgrade Ubuntu from 24.04 to 26.04 in GitHub Actions (#152717)
* Replace "ubuntu-24.04" with "ubuntu-26.04".
* Replace "ubuntu-latest" with "ubuntu-26.04" for Cross build Linux.
* Replace "ubuntu-latest" with "ubuntu-slim" for small workloads.
* Update ".github/actionlint.yaml" to allow "ubuntu-26.04"
and "ubuntu-26.04-arm" images.
* Install Ubuntu libmpdec-dev package, rather than installing libmpdec
from source (tarball).
* No longer run https://apt.llvm.org/llvm.sh, since ubuntu-26.04 provides
clang-21 by default.
Victor Stinner [Fri, 10 Jul 2026 00:18:41 +0000 (02:18 +0200)]
[3.15] gh-152132: Fix bugs in Py_RunMain() (#153461) (#153466)
* Check for signals more often. Previously, a pending exception could
be removed by PyErr_Clear().
* Only call _PyInterpreterState_SetNotRunningMain() if
_PyInterpreterState_SetRunningMain() has been called.
* Convert _PyPathConfig_UpdateGlobal() PyStatus error to an
exception.
[3.15] gh-153406: Raise ValueError, not OverflowError, for out-of-range dates in email.utils.parsedate_to_datetime (GH-153407) (#153435)
email.utils.parsedate_to_datetime documented that it raises ValueError for an invalid date, but it leaked OverflowError when the parsed year or timezone offset was too large for the datetime and timedelta constructors, and that OverflowError also escaped the modern header parsing path since DateHeader.parse only caught ValueError. Wrap the datetime and timezone construction so an OverflowError is re-raised as a ValueError with the original chained as the cause, which restores the documented contract and lets the existing header handler record an InvalidDateDefect instead of raising.
(cherry picked from commit 37a26b9b94b147b5d683bfce0ef5a4c2fbc21085)
[3.15] gh-152132: Fix Py_RunMain() to return an exit code (GH-153446) (#153454)
gh-152132: Fix Py_RunMain() to return an exit code (GH-153446)
* Fix Py_RunMain() to return an exit code, rather than calling
Py_Exit(), when running a script, a command, or the REPL.
* _PyRun_SimpleFile() now logs errors to stderr, for example if setting
__main__.__file__ fails.
* Add tests on Py_RunMain() exitcode.
* Rename functions:
* Change _PyRun_SimpleString(), _PyRun_SimpleFile(), _PyRun_AnyFile() and
_PyRun_InteractiveLoop() return type to PyObject*.
* pymain_repl() now displays the error if PySys_Audit() or
import _pyrepl failed.
* PyRun_SimpleFileExFlags() and PyRun_AnyFileExFlags() now log
PyUnicode_DecodeFSDefault() error. So these functions can no longer
return -1 with an exception set.
(cherry picked from commit fac72f1ee91fb380640a4c4be6df07a8f02d3110)
Co-authored-by: Victor Stinner <vstinner@python.org>
[3.15] gh-153422: Assert bool return type in tkinter tests (GH-153429) (GH-153439)
The tests for PhotoImage.transparency_get(), Text.debug() and
Treeview.exists() now assert the exact bool type, and the documentation
and docstrings use "true"/"false" instead of "1"/"0".
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
[3.15] gh-153417: Fix BytesWarning in imaplib error messages for bytes arguments (GH-153423) (GH-153430)
IMAP4.select() and IMAP4.uid() formatted the mailbox and command argument
with %s in their error messages, which raised BytesWarning under -bb when the
argument was bytes and masked the real error. Use %r instead, which is safe
for bytes and also quotes the value.
(cherry picked from commit 11f1b70f4c981b781aaa94427dc1fceb637b2187)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
[3.15] gh-152132: Test all PyRun functions in test_capi.test_run (GH-153352) (#153411)
gh-152132: Test all PyRun functions in test_capi.test_run (GH-153352)
PyRun_InteractiveOneObjectEx() now raises TypeError if the second
parameter type is not str.
(cherry picked from commit cd9994e2831ea743e5423c1db56ca2ca42154e0a)
Co-authored-by: Victor Stinner <vstinner@python.org>
identify(5, 5) could run before the notebook reached its requested size,
so the pixel fell outside the first tab and returned ''. Guard it with a
new opt-in wait_until_mapped(full_size=True).
(cherry picked from commit 53b04980284b668c27fc6d5adb0de19d38efe95b)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
- selectmode: new 'single' and 'multiple' modes
- set(): includes the tree column '#0'
- insert()/selection(): item ids keep the passed value's type
- heading_callback: avoid a double click on the second click
- theme_create_image: don't assert the exact (now scaled) width
(cherry picked from commit d6855c8ad00ffa2bee318b510d0e90573dddbbab)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
[3.15] gh-47005: fix do_open() to let regular headers override unredirected … (GH-146506) (#153377)
gh-47005: fix do_open() to let regular headers override unredirected … (GH-146506)
AbstractHTTPHandler.do_open() was building the request header dict by
starting with unredirected_hdrs and only inserting regular headers that
were not already present, giving unredirected headers priority. This
contradicts get_header() and header_items(), both of which give regular
headers the higher priority.
Fix by unconditionally updating with req.headers so that a header set
via add_header() always overrides one set via add_unredirected_header().
[3.15] gh-119592: gh-152967: Fix ProcessPoolExecutor stranding submitted work when a max_tasks_per_child worker exits (GH-152978) (#153363)
gh-119592: gh-152967: Fix ProcessPoolExecutor stranding submitted work when a max_tasks_per_child worker exits (GH-152978)
gh-119592: Fix ProcessPoolExecutor stranding submitted work when a max_tasks_per_child worker exits
Worker replacement went through the executor object: the manager thread
read executor attributes that shutdown(wait=False) clears concurrently,
and could not replace workers at all once the executor was garbage
collected. A worker exiting at its max_tasks_per_child limit in those
states left the remaining submitted work permanently unexecuted and hung
interpreter exit; the racing case could crash the manager thread.
Replace workers from the executor manager thread using its own state
plus configuration read through the live executor weakref, which
shutdown() never clears:
- After shutdown(wait=False) with the executor still referenced, a
replacement is spawned and the remaining work is executed as
documented.
- Once the executor has been garbage collected (gh-152967), or a
replacement worker cannot be started and no workers remain, the
remaining futures now fail with BrokenProcessPool instead of never
resolving.
- A new _force_shutting_down flag stops both spawn paths from starting
workers that would escape terminate_workers()/kill_workers().
(cherry picked from commit 0c6422ff6a13ae309493fb7a358cb35d7ea959c8)
Reviewed-multiple-times-by: Gregory P. Smith Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
[3.15] gh-153300: Set global configuration variables in PyConfig_Set() (GH-153301) (#153356)
gh-153300: Set global configuration variables in PyConfig_Set() (GH-153301)
PyConfig_Set() now also set global configuration variables. For
example, PyConfig_Set("inspect", value) now also sets Py_InspectFlag.
Use PyConfig_Set() in main.c to set the inspect flag. Python code can
now see the updated sys.flags.inspect value.
(cherry picked from commit 9fb713f1b8b774c789db007e3824c766a626ccff)
Co-authored-by: Victor Stinner <vstinner@python.org>
[3.15] gh-150191: temporarily skip two openssl tests which have internal data races under TSAN (GH-153320) (#153350)
gh-150191: temporarily skip two openssl tests which have internal data races under TSAN (GH-153320)
(cherry picked from commit c11af48fddb1fd5b38e2f026c333e8487f3bcc53)
[3.15] gh-143990: Preserve the size when creating a Font from a named font (GH-153267) (GH-153323)
tkinter.font.Font now copies the options of a named font (via "font
configure") instead of the options resolved by "font actual", which
would resolve a size specified in pixels (a negative size) to points.
A font description is still resolved, as it cannot be parsed otherwise.
Font.copy(), which has always been equivalent to constructing a Font
from the original font, is updated to match and now preserves the size
too.
[3.15] gh-88574: Do not swallow the line after a terminating literal in imaplib (GH-153317) (GH-153324)
GH-152751 skipped a spurious blank line after a literal unconditionally,
corrupting a response that ends with a literal (such as a mailbox name
returned by LIST): its empty trailer was mistaken for the blank and the
following line was swallowed.
The blank is now skipped only inside an unclosed parenthesis. After a
literal that ends the response it instead arrives before the next
response and is skipped there.
(cherry picked from commit 6b81784f57c6e7ddef61c8db26bb896b3633dcae)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
[3.15] gh-86017: Document displayof for Font.actual() and clarify Font.copy() (GH-153288) (GH-153329)
Explain the displayof argument of tkinter.font.Font.actual() and describe
what Font.copy() returns, including for a wrapped font description.
(cherry picked from commit fa5eafd19c3d395b4498e21b4e1b8faac2ebdb0a)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
[3.15] gh-153056: Fix a data race compiling the string.Template pattern in free-threading builds (GH-153057) (#153302)
gh-153056: Fix a data race compiling the string.Template pattern in free-threading builds (GH-153057)
* gh-153056: Fix a data race compiling the string.Template pattern in free-threading builds
Template compiles its substitution pattern lazily and caches it on the class. On the free-threaded build two concurrent first uses could race: a thread that observed the pattern another thread had just compiled would try to recompile it, and re.compile() rejects flags on an already-compiled pattern, raising a spurious ValueError. Return the already-compiled pattern instead.
As a side effect, a subclass that supplies an already-compiled pattern now works too; previously it raised the same ValueError at class definition.
* Trim test comments and NEWS wording
* Document that the pattern attribute accepts a string or a compiled regex
* Comment the three states of pattern and note the documented-behavior fix in NEWS
Co-authored-by: An Long <aisk@users.noreply.github.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: sobolevn <mail@sobolevn.me>
[3.15] gh-83274: Don't crash when a Tcl interpreter is deallocated in the wrong thread (GH-152323) (GH-153271)
Deallocating the interpreter from a thread other than the one it was created
in ran Tcl_DeleteInterp() there, which makes Tcl abort the process
("Tcl_AsyncDelete: async handler deleted by the wrong thread").
Tkapp_Dealloc() now leaks the interpreter in that case and reports a
RuntimeWarning instead.
[3.15] gh-153200: Fix math.isqrt() for int subclasses with overridden comparison operators (GH-153203) (GH-153223)
The final check-and-correct comparison in the arbitrary precision path
could call a comparison operator overridden in an int subclass.
Compare by value with int's tp_richcompare.
(cherry picked from commit 3a1b5473f217fc493f743c9ca8b877d2e76f8e6b)