Serhiy Storchaka [Thu, 25 Jun 2026 12:05:46 +0000 (15:05 +0300)]
gh-127802: Schedule removal of legacy tkinter variable trace methods in 3.17 (GH-152012)
The tkinter.Variable methods trace_variable(), trace(), trace_vdelete()
and trace_vinfo(), deprecated since Python 3.14, are now scheduled for
removal in Python 3.17.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Thu, 25 Jun 2026 08:09:56 +0000 (11:09 +0300)]
gh-152100: Move re compiler optimizations to Lib/re/_optimizer.py (GH-152154)
Move the compile-time optimizations (_optimize_charset, _compile_charset,
_simple, _compile_info and the literal/charset prefix helpers) out of
_compiler.py into a new Lib/re/_optimizer.py. _compiler.py keeps only the
bytecode emitter and imports them. This is groundwork for a follow-up
optimization; there is no behavior change.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Thu, 25 Jun 2026 07:09:41 +0000 (10:09 +0300)]
gh-152100: Support set operations in character classes (GH-152153)
Implement set difference [A--B], intersection [A&&B] and union [A||B] in
regular expression character classes (Unicode Technical Standard #18),
including nested, complemented and compound set operands. Symmetric
difference [A~~B] remains reserved.
Also use the new syntax in the standard library (_strptime, textwrap,
doctest, pkgutil).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Add window methods and module functions that report curses state which could
previously only be set: the window getters is_cleared(), is_idcok(),
is_idlok(), is_immedok(), is_keypad(), is_leaveok(), is_nodelay(),
is_notimeout(), is_pad(), is_scrollok(), is_subwin(), is_syncok(),
getdelay(), getparent() and getscrreg(), and the functions is_cbreak(),
is_echo(), is_nl() and is_raw(). They are available when built against an
ncurses with NCURSES_EXT_FUNCS.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add alloc_pair(), find_pair(), free_pair() and reset_color_pairs(),
wrapping the ncurses extended-color dynamic pair management. They are
available only when built against a wide-character ncurses with
extended-color support.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Wed, 24 Jun 2026 18:10:16 +0000 (21:10 +0300)]
gh-86726: Improve the structure of the tkinter reference (GH-152109)
Add short group intros before each cluster of Misc methods.
Group the Tk and Toplevel classes in a new "Toplevel widgets" section, move
the Tcl() function to the module-level functions, and move the "File
handlers" section into the reference.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Benjy Wiener [Wed, 24 Jun 2026 14:11:02 +0000 (17:11 +0300)]
gh-151485: Fix command quoting in subprocess.CalledProcessError.__str__ (#151486)
CalledProcessError previously formatted cmd as `"... '%s' ..."`. This lead to
unbalanced quoting when cmd contains single-quotes or, more commonly, when cmd
is a list. This change updates the relevant format strings to use %r instead.
Co-authored-by: Benjy Wiener <benjywiener@gmail.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
gh-151456: Document the show_jit parameter in dis (#151457)
show_jit was added to dis.dis(), distb(), disassemble(), get_instructions() and the Bytecode class (gh-150478) but was never documented. Document it across those APIs with a versionchanged:: 3.16 note, and fix a pre-existing show_offset -> show_offsets typo in the distb signature.
Serhiy Storchaka [Wed, 24 Jun 2026 11:33:02 +0000 (14:33 +0300)]
gh-90092: Support multiple terminals in the curses module (GH-151748)
Add the X/Open Curses SCREEN API for driving more than one terminal:
newterm() and set_term(), plus the ncurses extension new_prescr().
A new screen object wraps the C SCREEN. It exposes the terminal's
standard window as screen.stdscr. Each window keeps a reference to its
screen (like a subwindow does to its parent window), so the screen is
deleted automatically once it and all of its windows are unreferenced.
The ncurses use_screen()/use_window() locking helpers are exposed as
the screen.use() and window.use() methods.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pieter Eendebak [Wed, 24 Jun 2026 11:09:50 +0000 (13:09 +0200)]
gh-152056: Compile single-category character sets to a bare CATEGORY opcode (GH-152057)
A character set containing exactly one category, e.g. [\d] or [^\s], now
compiles to a single CATEGORY opcode (like \d or \S) instead of an IN
block. The negated form maps to the complementary category. This speeds
up matching and reduces the size of the compiled byte code.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Wed, 24 Jun 2026 06:30:17 +0000 (09:30 +0300)]
gh-84008: Document that the LC_NUMERIC locale affects tkinter numeric widgets (GH-152008)
Spinbox, Scale and ttk.Spinbox format floating-point values according to
the LC_NUMERIC locale, but such values are always parsed with a period, so
a comma-decimal locale breaks DoubleVar.get().
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Wed, 24 Jun 2026 06:08:34 +0000 (09:08 +0300)]
gh-87904: Document curses classes (GH-151643)
Add docstrings for the curses.window, curses.error, curses.panel.panel
and curses.panel.error classes. Document the panel class and its error
exception in curses.panel.rst, using the real lowercase panel name.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Wed, 24 Jun 2026 05:52:10 +0000 (08:52 +0300)]
gh-151757: Support wide and combining characters in the curses module (GH-151758)
The character-cell window methods now accept a full character cell -- a
spacing character optionally followed by combining characters (up to
CCHARW_MAX wide characters) -- in addition to a single int or byte
character. This affects addch(), bkgd(), bkgdset(), border(), box(),
echochar(), hline(), insch() and vline(); they dispatch to the ncursesw
wide-character functions (wadd_wch(), wbkgrnd(), wborder_set(),
wecho_wchar(), whline_set(), wins_wch(), wvline_set(), ...) when given a
string. border() and box() cannot mix integer or byte characters with
wide string characters in a single call. A cell is one spacing character
optionally followed by combining characters, so an extra spacing or
control character (such as "ab") is rejected with ValueError rather than
being silently truncated by setcchar().
Also add the wide-character read methods get_wstr() and in_wstr(), the
counterparts of getstr() and instr() that return a str rather than a
bytes object, and the module functions erasewchar(), killwchar() and
wunctrl(), the wide-character counterparts of erasechar(), killchar()
and unctrl().
All of this is available only when built against the wide-character
ncursesw library.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Wed, 24 Jun 2026 05:49:14 +0000 (08:49 +0300)]
gh-152033: Optimize category escapes outside character sets (GH-152035)
Character class escapes (``\d``, ``\D``, ``\s``, ``\S``, ``\w`` and
``\W``) that occur outside a character set are now compiled directly to a
single CATEGORY opcode instead of being wrapped in an IN block. This
removes the IN wrapper (three code words) and an indirect charset() call,
and makes such an escape a simple repeatable unit so that, for example,
``\d+`` uses the REPEAT_ONE fast path; a CATEGORY case is added to
SRE(count).
The transformation preserves behaviour exactly. For category-heavy
patterns the compiled byte code is about 20% smaller and matching is up
to ~2x faster, with no effect on patterns that do not use bare category
escapes.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The size is taken from the archive and is not validated, so a ~512-byte
crafted file can claim several gigabytes (or, via base-256 encoding, far
more) and make read() pre-allocate that much memory -- on open/iterate,
before any extraction filter runs.
Read the extended-header data in bounded chunks instead, so an oversized
or truncated header can no longer force a huge allocation. The bytes
returned for valid archives are unchanged.
Rework SimpleDialog and Dialog to match the look and feel of the native Tk
dialogs ::tk_dialog and ::tk::MessageBox.
* SimpleDialog is a Python port of ::tk_dialog and Dialog a base class
modelled on ::tk::MessageBox. Both adopt the message-box keyboard
conventions: button accelerators, a default ring that follows the keyboard
focus, and a <Return> binding that invokes the focused button.
* Both classes gain a use_ttk parameter that selects the classic Tk or the
themed ttk widgets. It controls the widget set and the appearance that the
two procedures style differently, but not the keyboard behaviour.
* Update _place_window with the Tk 9.1 placement refinements.
* The new helpers _temp_grab_focus (a modal grab/focus context manager),
_underline_ampersand and _find_alt_key_target (ports of the Tk
accelerator-key procedures) can be reused by other tkinter dialogs, as
_setup_dialog already is.
* Fix several defects uncovered while comparing with the Tcl sources.
* Improve the simpledialog demo.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Tue, 23 Jun 2026 06:24:17 +0000 (09:24 +0300)]
gh-101284: Allow passing Menubutton options to tkinter.OptionMenu (GH-151959)
Arbitrary keyword arguments are now forwarded to the underlying
Menubutton and can override OptionMenu's default appearance options.
The positional API is unchanged.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Mon, 22 Jun 2026 17:43:43 +0000 (20:43 +0300)]
gh-151920: Add the ttk.Style.theme_styles() method (GH-151921)
Wrap the Tk 9.0 ``ttk::style theme styles ?themeName?`` subcommand as
ttk.Style.theme_styles(themename=None), returning the list of styles
defined in a theme (the current theme if themename is omitted).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Mon, 22 Jun 2026 17:31:25 +0000 (20:31 +0300)]
gh-151886: Add tkinter Misc.tk_appname, tk_useinputmethods and tk_caret (GH-151887)
Wrap three long-standing Tk commands that had no tkinter wrapper:
* Misc.tk_appname() queries or sets the name used to communicate with the
application through the send command (Tk 8.5).
* Misc.tk_useinputmethods() queries or sets whether Tk uses the X Input
Methods (XIM) for filtering events (Tk 8.5).
* Misc.tk_caret() sets or queries the per-display caret location used for
accessibility and for placing the input method window (Tk 8.5).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Mon, 22 Jun 2026 16:35:39 +0000 (19:35 +0300)]
gh-151890: Support more photo image options in tkinter.PhotoImage methods (GH-151891)
Add parameters mapping to Tk photo image options that previously had no
tkinter equivalent:
* the format parameter of PhotoImage.put() (Tk 8.6),
* the metadata parameter of PhotoImage.put(), read(), write() and data()
(Tk 9.0),
* the withalpha parameter of PhotoImage.get() (Tk 9.0).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Fixes issue #150162 by improving the code introduced by 70154855cf69
(GH-127729) while retaining the original documented intent. The
aforementioned code has a side effect when used in a virtual environment
context, on posix platforms, with the cross-compiling environment
variable _PYTHON_PROJECT_BASE present. In this case, every single
sysconfig.get_config_vars() and sysconfig.get_config_var() call, forces
the _CONFIG_VARS dictionary to be reinitialised from scratch. This is
inefficient, but also means no changes to the dictionary returned by
sysconfig.get_config_vars() persist, which can be useful in certain
situations.
This commit tracks changes to sys.prefix and sys.exec_prefix more
directly rather than relying on a misalignment with the corresponding
sysconfig variables.
Bernát Gábor [Mon, 22 Jun 2026 15:39:08 +0000 (08:39 -0700)]
gh-140006: Harden fish prompt against shadowed builtins (#150936)
A user function that shadows the `.`/`source` builtin hijacks the
activate.fish prompt. fish resolves functions ahead of builtins, so the
`echo "exit $status" | .` line that restores the exit status pipes into
the user function instead of sourcing. Dot-style directory navigators
redefine `.`, which made the prompt list the directory on every command
and dropped the exit status handed to the original prompt.
Route every builtin the prompt path uses (`source`, `echo`, `printf`,
`set_color`, `functions`) through `builtin` so no user function can
intercept them. These have all been fish builtins with a stable
interface since fish 2.0.0, the version the script already required
through `functions --copy`, so the minimum supported fish version does
not change.
Wrap the photo image "redither" Tk command (since Tk 8.5) as the method
PhotoImage.redither(), which recalculates the dithered image in each
window where it is displayed (useful when the image data was supplied in
pieces), completing the wrapping of the photo image subcommands.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Ronan Pigott [Mon, 22 Jun 2026 14:40:23 +0000 (07:40 -0700)]
gh-111501: venv: do not export PS1 in activate (#105279)
PS1 is a parameter special to the current interactive shell. It does not
need to be exported to the environment. Exporting PS1 is not useful, and
will break different shells spawned by the current interactive shell.
_andthereitgoes [Mon, 22 Jun 2026 14:07:39 +0000 (00:07 +1000)]
Correct typos in `runpy.run_path` documentation (#151230)
*file_path* -> *path_name* in runpy.rst
The documentation for runpy.run_path refers to a parameter called *file_path*, which doesn't exist in the call spec. However, *path_name* exists, and it is implied that *file_path* actually refers to *path_name*.
Serhiy Storchaka [Mon, 22 Jun 2026 13:53:02 +0000 (16:53 +0300)]
gh-151881: Add tkinter Menu.postcascade, Misc.tk_scaling and tk_inactive (GH-151882)
Wrap three long-standing Tk commands that had no tkinter wrapper:
* Menu.postcascade() posts the submenu of a cascade entry (Tk 8.5),
complementing the existing post() and unpost() methods.
* Misc.tk_scaling() queries or sets the scaling factor in pixels per
point used to convert between physical units and pixels (Tk 8.4).
* Misc.tk_inactive() returns the user idle time in milliseconds, and can
reset that timer (Tk 8.5).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Mon, 22 Jun 2026 13:51:50 +0000 (16:51 +0300)]
gh-151876: Add tkinter Canvas methods rotate and rchars (GH-151877)
Wrap the Tk canvas commands "rchars" (replace the text or coordinates of
items, since Tk 8.6) and "rotate" (rotate the coordinates of items about
an origin, new in Tk 9.0) as the methods Canvas.rchars() and
Canvas.rotate(), complementing the existing dchars/insert and move/scale
methods.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Mon, 22 Jun 2026 12:52:50 +0000 (15:52 +0300)]
gh-151878: Add tkinter Entry and Spinbox validate methods (GH-151879)
Wrap the Tk "validate" widget command of the entry and spinbox widgets as
the methods Entry.validate() and Spinbox.validate(), forcing an evaluation
of the validatecommand independently of the validate option and returning
whether the value is valid.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Document where widget methods shadow inherited Misc, geometry-manager and
Wm methods, correct the inaccurate "size/bbox is an alias of
grid_size/grid_bbox" claims, and add "# overrides X" comments at the
definitions.
Also document the geometry-manager ambiguity: the short names forget, info,
slaves, content and propagate are defined by Pack, Place and Grid but
resolve to the pack variant.
Cross-reference the window-manager methods grid, forget and state with the
same-named grid geometry manager, Pack.forget and ttk.Widget.state.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Mon, 22 Jun 2026 12:13:50 +0000 (15:13 +0300)]
gh-151874: Add tkinter wm_stackorder, wm_iconbadge and winfo_isdark (GH-151875)
Wrap the Tk commands "wm stackorder" (toplevel stacking order, since
Tk 8.4), "wm iconbadge" (application icon badge, new in Tk 9.0) and
"winfo isdark" (dark mode detection, new in Tk 9.0) as the methods
Wm.wm_stackorder(), Wm.wm_iconbadge() and Misc.winfo_isdark(), with the
usual stackorder and iconbadge short aliases.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
The test forced a rollover by back-dating the file modification time, but
the rollover time is now based also on the creation time, which cannot be
changed. Instead, set the rollover time one second after the file
creation time and wait until the clock reaches it.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Sat, 20 Jun 2026 14:31:40 +0000 (17:31 +0300)]
gh-151678: Add tests for tkinter widget virtual events (GH-151793)
Verify the virtual events that widgets emit in response to user
interaction, driven by generated events: <<ListboxSelect>> (Listbox),
<<Increment>> and <<Decrement>> (ttk Spinbox), and <<TreeviewSelect>>,
<<TreeviewOpen>> and <<TreeviewClose>> (ttk Treeview).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Sat, 20 Jun 2026 14:11:21 +0000 (17:11 +0300)]
gh-151675: Add tkinter Text.sync() and Text.pendingsync() (GH-151677)
Wrap the Tk text widget "sync" and "pendingsync" subcommands, which
control and report the synchronization of the displayed view with the
underlying text when line heights have not yet been computed.