Serhiy Storchaka [Sat, 27 Jun 2026 07:10:11 +0000 (10:10 +0300)]
gh-87904: Report the public module name in curses types and exceptions (GH-152341)
The curses C types and exceptions now set their tp_name to the public
module, so __module__, repr() and help() report curses.window,
curses.complexchar, curses.complexstr, curses.screen, curses.error,
curses.panel.panel and curses.panel.error instead of the underscore
extension modules.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Sat, 27 Jun 2026 07:09:07 +0000 (10:09 +0300)]
gh-151678: Add more tests for tkinter.dnd (GH-152362)
Cover the drag cursor, the Motion and ButtonRelease bindings, switching
between targets, the target search up the master chain, dnd_accept()
returning None, and restarting after a drag has finished.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Sat, 27 Jun 2026 07:08:04 +0000 (10:08 +0300)]
gh-71880: Allow editing the last cell in curses.textpad.Textbox (GH-152363)
Textbox.edit() ignored typing in the lower-right cell of the window. It is
now written with insch(), which fills the cell without moving the cursor out
of the window (addch() there raises an error and scrolls a scrollable window).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Fri, 26 Jun 2026 23:00:38 +0000 (02:00 +0300)]
gh-88758: Handle non-tkinter widgets in tkinter focus methods (GH-152337)
focus_get(), focus_displayof(), focus_lastfor() and winfo_containing()
now return None instead of raising KeyError when the focused widget was
not created by tkinter (for example a torn-off menu).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Add define_key(), key_defined() and keyok(), the ncurses extensions for
managing how control strings are recognized as key codes, beyond the
predefined terminfo keys and the all-or-nothing window.keypad().
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Fri, 26 Jun 2026 22:45:30 +0000 (01:45 +0300)]
gh-152260: Fix test_scr_dump() on macOS (GH-152340)
The dump format embeds raw pointers on some platforms, so two dumps of the
same screen are not always byte-identical. Only compare dump files when
the format proves deterministic.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Fri, 26 Jun 2026 18:52:10 +0000 (21:52 +0300)]
gh-80937: Fix memory leak in tkinter createcommand (GH-152294)
A command created with createcommand() held a strong reference to the
interpreter, forming an uncollectable cycle (interpreter -> command ->
interpreter) that kept the interpreter and the callback alive until the
command was removed with deletecommand() or destroy(). The command now
borrows the reference; it cannot outlive the interpreter, which deletes its
commands when finalized.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Neil Schemenauer [Fri, 26 Jun 2026 18:20:41 +0000 (11:20 -0700)]
gh-152238: Revert gh-150490 and gh-152200. (gh-152232)
Revert commits:
gh-151593: Fix dead lock in PyDict insert_split_key() (#152200)
gh-150490: Raise PyType_Modified for insertion into split dictionary (#150489)
For gh-150489, it violates locking discipline and results in deadlocks,
gh-151593 is an example of it being hit in CI. The attempted fix
gh-152200 avoids the deadlock but introduces a data-race. The race
window is small but can be triggered with pure Python code.
Serhiy Storchaka [Fri, 26 Jun 2026 16:36:31 +0000 (19:36 +0300)]
gh-152260: Add curses.scr_dump(), scr_restore(), scr_init() and scr_set() (GH-152261)
These module-level functions write the whole virtual screen to a file and
load it back -- the screen-wide counterpart of window.putwin()/getwin().
The filename argument accepts a string or a path-like object.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Fri, 26 Jun 2026 15:50:30 +0000 (18:50 +0300)]
gh-151776: Fix test_state_getters on terminals without insert/delete capability (GH-152304)
idcok() and idlok() take effect only when the terminal can insert or
delete characters or lines, so check their getters against the
terminal's capabilities instead of asserting an unconditional round-trip.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Fri, 26 Jun 2026 14:28:53 +0000 (17:28 +0300)]
gh-152258: Add curses.window.dupwin() (GH-152259)
dupwin() returns a new window that is an independent duplicate of an existing
one -- same size, position, contents and attributes, but with its own cell
buffer, so changes to one do not affect the other.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Fri, 26 Jun 2026 14:14:43 +0000 (17:14 +0300)]
gh-139145: Fix tkinter event loop in interactive mode (GH-152257)
When a Tcl command running its own event loop (such as vwait or
wait_variable) was active and the user typed input on stdin, the event
loop kept spinning at 100% CPU. The stdin file handler is now removed as
soon as input becomes available.
Also fix gh-139816: an exception raised in a callback no longer stops the
event loop to wait for Enter on a Python built without readline; pending
callbacks keep running until input is actually available on stdin.
Co-authored-by: mdehoon <mjldehoon@yahoo.com> Co-authored-by: Christopher Chavez <chrischavez@gmx.us> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Victor Stinner [Fri, 26 Jun 2026 11:55:54 +0000 (13:55 +0200)]
gh-151722: Defer GC tracking in frozendict.copy() (#152230)
Fix _PyDict_Or() and frozendict.copy(): only track the frozendict by
the GC once the dictionary is fully initialized.
Functions modifying frozendict now ensures that the object is not
tracked by the GC (in debug mode).
* can_modify_dict() checks that _PyObject_GC_IS_TRACKED() is false
for frozendicts.
* dict_merge_api() makes sure that the dictionary is tracked by the
GC.
Marcel Martin [Fri, 26 Jun 2026 11:46:39 +0000 (13:46 +0200)]
gh-90533: Implement BytesIO.peek() (#150917)
Add io.BytesIO.peek() method to read without advancing position.
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Emma Smith <emma@emmatyping.dev> Co-authored-by: Stan Ulbrych <stan@python.org> Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
Serhiy Storchaka [Fri, 26 Jun 2026 11:37:30 +0000 (14:37 +0300)]
gh-152233: Add curses complexstr type and wide-character cell-array methods (GH-152262)
Add the immutable curses.complexstr type, an array of styled wide-character
cells -- the string counterpart of complexchar. It is constructible from an
iterable of cells (each a complexchar or a str) or from a string split into
cells, with optional attr and pair applied to every cell. It is an immutable
sequence (indexing yields a complexchar, slicing and concatenation yield a
complexstr), is hashable, and str() returns its cells' text.
Add the window method in_wchstr(), the wide-character counterpart of instr()
and in_wstr() that keeps each cell's attributes and color pair instead of
stripping them; it returns a complexstr.
The methods addstr(), addnstr(), insstr() and insnstr() now also accept a
complexstr, so a run read with in_wchstr() can be written back unchanged. The
cells carry their own rendition, so combining one with an explicit attr raises
TypeError.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Fri, 26 Jun 2026 11:15:12 +0000 (14:15 +0300)]
gh-95555: Allow a negated property as a character set member (GH-152245)
A negated multi-range property such as \P{ASCII} or \P{Pattern_Syntax} was
rejected inside a character class. Such members are now alternated in with
the other members: [\P{ASCII}abc] becomes [abc] | [^ASCII], and [\P{ASCII}]
alone is just the negated charset.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Fri, 26 Jun 2026 11:12:46 +0000 (14:12 +0300)]
gh-152100: Fuse set-operation character classes into a single charset (GH-152214)
Add a compile-time optimization pass (Lib/re/_optimizer.py) that rewrites
set-operation character classes into a single character set where the
engine's charset() representation allows it. charset() treats every NEGATE
as a polarity toggle, so a mid-list NEGATE expresses set difference and a
flat run expresses union.
Set difference -- [A--B], emitted by the parser as A(?<![B]) -- fuses into
the charset [NEGATE] B [NEGATE] A, matching A minus B in one test instead of
a charset match plus a lookbehind rescan. _optimize_charset is made
segment-aware so the interior NEGATE compiles correctly.
A union with a non-flat operand, such as [0-9||[a-z--b]], is emitted by the
parser as a BRANCH that it cannot merge. Once its alternatives are all
one-character matchers, their item lists are concatenated into a single IN.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Fri, 26 Jun 2026 10:49:17 +0000 (13:49 +0300)]
gh-152233: Add curses complexchar type and wide-character cell reads (GH-152250)
Add the immutable `curses.complexchar` type: a styled wide-character cell — a spacing character optionally followed by combining characters, plus attributes and a color pair. The color pair is stored separately rather than packed into a `chtype` via `COLOR_PAIR()`, so it is not limited to the values that fit alongside the attribute bits. `str(cc)` returns the text; the read-only `attr` and `pair` attributes return its rendition.
Add the window methods `in_wch()` and `getbkgrnd()` — the wide-character counterparts of `inch()` and `getbkgd()` — which return a `complexchar`. (`inch()`/`getbkgd()` can only return a packed `chtype`, so these fill a real gap; this resolves the long-standing gh-83395 request for `in_wch`.)
The existing character-cell methods (`addch`, `insch`, `echochar`, `bkgd`, `bkgdset`, `border`, `box`, `hline`, `vline`) now also accept a `complexchar`. A `complexchar` already carries its own rendition, so passing one together with an explicit `attr` argument raises `TypeError`.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Add the window methods attr_get(), attr_set(), attr_on(), attr_off() and
color_set(), wrapping wattr_get(), wattr_set(), wattr_on(), wattr_off() and
wcolor_set(). Unlike the legacy attron()/attroff()/attrset() methods, these
pass the color pair as a separate argument instead of packing it into the
attribute value. Also add the corresponding WA_* attribute constants.
Add an attr_converter that range-checks the attr_t attribute argument and
raises OverflowError instead of silently truncating it; apply it to attr_set(),
attr_on(), attr_off() and chgat().
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Fri, 26 Jun 2026 04:33:33 +0000 (07:33 +0300)]
gh-95555: Support Unicode property escapes \p{...} in regular expressions (GH-151969)
Add support for \p{property} and \P{property} escapes in Unicode (str)
regular expressions, for the properties the engine can resolve without
the unicodedata database. They are matched as CATEGORY opcodes or as
fixed sets of character ranges.
Supported in this change: many General_Category values (the groups L, N,
Z, C and the values Lu, Lt, Lm, Nd, Nl, No, Zs, Zl, Zp, Cc, Cf, Cs, Co
and Cn); the binary properties Alphabetic, Lowercase, Uppercase, Numeric,
Printable, XID_Start, XID_Continue, Cased and Case_Ignorable; the POSIX
compatibility classes; the code-point classes ASCII, Any, Assigned,
Noncharacter_Code_Point, Join_Control, Pattern_Syntax and
Pattern_White_Space; and Regional_Indicator, ASCII_Hex_Digit and
Hex_Digit.
Property and value names use loose matching (UAX #44 UAX44-LM3), so a
property may be spelled \p{Lu}, \p{gc=Lu} or \p{name=yes}.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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>