Commit graph

132002 commits

Author SHA1 Message Date
Serhiy Storchaka
7bf63facfd
gh-152275: Add integer overflow guards to the curses chtype and color-pair packing path (GH-152303)
curses.color_pair() now raises OverflowError for a pair number too large
to be packed, instead of silently masking it to a different pair.

The attr argument of the character-cell and attribute methods (addch,
addstr, attron, attrset and others) now goes through the checked attr
converter, so an out-of-range or non-integer attribute is rejected rather
than silently truncated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 15:42:41 +03:00
Serhiy Storchaka
3fa72d5c2e
gh-152260: Fix flaky curses test_scr_dump on macOS (GH-152390)
The screen dump embeds raw pointers that change after scr_restore(),
so comparing dump bytes is unreliable.  Test the round-trip functionally
instead.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 11:59:53 +00:00
Serhiy Storchaka
4fd69ef97a
gh-70273: Document default class bindings in tkinter (GH-152389)
Note in the Bindings and events section that every widget inherits Tk
class bindings for its standard behavior, where they are documented, and
how to suppress an unwanted one by returning "break" from a callback.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 14:37:41 +03:00
Serhiy Storchaka
ea7f64a65c
gh-82830: Improve tkinter messagebox docstrings and cursor documentation (GH-152380)
Document Windows cursor files (gh-99089).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 14:01:34 +03:00
tonghuaroot (童话)
93454fe0da
gh-152212: Reject a POSIX TZ footer with a missing std offset in pure-Python zoneinfo (#152213) 2026-06-27 10:16:43 +01:00
Kumar Aditya
b3154aa450
gh-127949: remove asyncio policy system (#150310) 2026-06-27 12:46:50 +05:30
Serhiy Storchaka
fd63e21c0b
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>
2026-06-27 10:10:11 +03:00
Serhiy Storchaka
389e00f13f
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>
2026-06-27 07:09:07 +00:00
Serhiy Storchaka
11b394381f
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>
2026-06-27 10:08:04 +03:00
Jonathan Dung
1812162f81
Remove commented out code 2026-06-26 18:27:47 -05:00
Serhiy Storchaka
5c3555bdc5
gh-38464: Make tkinter nametowidget() work with cloned menus (GH-152336)
Map the auto-generated name of a cloned menu (a menu used as a menubar
or a cascade) back to the original widget instead of raising KeyError.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 02:02:52 +03:00
Serhiy Storchaka
5fed5ce85d
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>
2026-06-27 02:00:38 +03:00
Serhiy Storchaka
8f4abfc392
gh-152334: Add curses key-management functions (GH-152338)
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>
2026-06-27 01:59:24 +03:00
Inada Naoki
74272d4f0b
IDLE: fix dedent() usage in htest (#152256)
Fix typos: in #112642, initial string concatenation quotes were left when switching to textwrap.dedent().
2026-06-26 18:47:33 -04:00
Serhiy Storchaka
1d6d33c33f
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>
2026-06-27 01:45:30 +03:00
Serhiy Storchaka
bbf7786a90
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>
2026-06-26 21:52:10 +03:00
Neil Schemenauer
9626ef87f4
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.
2026-06-26 11:20:41 -07:00
Donghee Na
5a549e82b8
gh-152235: Defer GC tracking in set.union and set.difference (gh-152290) 2026-06-26 17:11:33 +00:00
Serhiy Storchaka
a85e73b322
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>
2026-06-26 16:36:31 +00:00
Serhiy Storchaka
bf61794fd2
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>
2026-06-26 15:50:30 +00:00
stratakis
671357691f
gh-98894: Skip test_dtrace when building without dtrace (#152239) 2026-06-26 14:48:12 +00:00
Serhiy Storchaka
49d484e4b1
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>
2026-06-26 14:28:53 +00:00
Serhiy Storchaka
3ffda34f5c
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>
2026-06-26 17:14:43 +03:00
tonghuaroot (童话)
588be7af08
gh-152052: Fix misleading json error for \uXXXX escape at the end of input (#152053)
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-26 14:47:22 +01:00
sobolevn
1cbe460eb6
gh-152236: Fix skips on _testcapi.set_nomemory tests (#152253) 2026-06-26 13:36:41 +00:00
Donghee Na
a87d24a69d
gh-152235: Defer GC tracking in more set operations (gh-152273) 2026-06-26 22:35:17 +09:00
Sergey B Kirpichev
5f17434a1e
gh-121249: Soft deprecate F and D struct format types (#149346)
Remove F/D type codes from table in the struct module documentation.

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-06-26 15:03:49 +02:00
Victor Stinner
05679f3576
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.
2026-06-26 13:55:54 +02:00
Marcel Martin
72cad148cb
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>
2026-06-26 13:46:39 +02:00
sobolevn
3ad66bf10d
gh-152156: Fix a crash in interpeters.create under limited memory conditions (#152163) 2026-06-26 14:41:55 +03:00
tonghuaroot (童话)
f47acc7f09
gh-152246: Fix pure-Python zoneinfo accepting invalid seperators in POSIX TZ rules (#152247)
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-26 12:39:26 +01:00
Serhiy Storchaka
55fe0e64f3
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>
2026-06-26 14:37:30 +03:00
Serhiy Storchaka
8eb6fb0294
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>
2026-06-26 14:15:12 +03:00
Serhiy Storchaka
d91e1038e8
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>
2026-06-26 14:12:46 +03:00
Serhiy Storchaka
8a01d28b7e
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>
2026-06-26 13:49:17 +03:00
Serhiy Storchaka
285d96dd78
gh-152219: Add curses window attribute get/set methods and WA_* constants (GH-152221)
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>
2026-06-26 07:48:53 +03:00
Serhiy Storchaka
794b42ff8a
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>
2026-06-26 07:33:33 +03:00
Donghee Na
908f438e19
gh-152235: Defer GC tracking of set and frozenset to end of construction (gh-152237) 2026-06-26 11:34:13 +09:00
Victor Stinner
55bc3126e0
gh-151722: Do not track the frozendict in the GC in _PyDict_FromKeys() (#152067)
_PyDict_FromKeys() now creates a frozendict copy which is
not tracked by the GC.

dict_merge() no longer requires the dictionary to be tracked by the
GC.

Co-authored-by: Donghee Na <donghee.na@python.org>
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
2026-06-25 18:06:07 +00:00
Victor Stinner
bef5706222
gh-151593: Fix dead lock in PyDict insert_split_key() (#152200)
Do not hold LOCK_KEYS() lock when calling PyType_Modified() to avoid
a deadlock.

Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
2026-06-25 19:58:27 +02:00
Victor Stinner
7c8163719c
gh-151929: Add pythoninfo commands to Platforms/WASI (#152136)
The "build" command now also runs "pythoninfo-build" and
"pythoninfo-host" commands.

If no subcommand is provided, display the help.

GitHub Action "WASI":

* Add "pythoninfo-build" and "pythoninfo-host" commands.
* Remove unused and outdated CROSS_BUILD_PYTHON environment variable.
2026-06-25 19:15:45 +02:00
Victor Stinner
7676427cd8
gh-151929: Add pythoninfo-build command to Platforms/emscripten (#152210)
* Add also "pythoninfo-host" command.
* Add pythoninfo to the "build" command.
2026-06-25 16:32:37 +00:00
Marc Mueller
56ae0b8e4f
gh-148825: Fix build error if specialization is disabled (#148826) 2026-06-25 14:06:22 +00:00
Shahar Naveh
11c241e1a8
Don't require _testcapi for test_code (#152185)
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-25 14:33:36 +01:00
Shahar Naveh
6a82832a0b
gh-152168: Don't skip test_bigmem if _testcapi is missing (#152171) 2026-06-25 14:30:49 +01:00
Victor Stinner
b6d89edc4a
gh-151929: Get uptime on BSD/macOS in pythoninfo (#152189)
* Check sysctlbyname() function and sys/sysctl.h header in
  configure.
* Add _testcapi.uptime_bsd() function.
2026-06-25 13:11:17 +00:00
Serhiy Storchaka
deeae2ac07
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>
2026-06-25 15:05:46 +03:00
Victor Stinner
f9910519af
gh-151929: Get machine ID and uptime on Windows in pythoninfo (#152146)
* Replace "linux." prefix with "system." in pythoninfo.
* Add _winapi.GetTickCount64() function.
2026-06-25 12:02:53 +00:00
Danny Lin
2b3ea68ceb
gh-51067: Refactor duplicated logic in zipfile to _read_local_file_header helper (#152139) 2026-06-25 12:58:28 +01:00
Ivy Xu
a580029f11
gh-151126: Add missing PyErr_NoMemory in _winapi.c (#151588)
Co-authored-by: sobolevn <mail@sobolevn.me>
2026-06-25 10:47:25 +00:00