Commit graph

15957 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
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
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
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
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
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
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
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
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
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
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
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
sobolevn
a0093282ea
gh-151126: Fix missing PyErr_NoMemory in testinternalcapi.c (#152177) 2026-06-25 09:48:23 +00:00
tonghuaroot (童话)
6f9c76d8d8
gh-152079: Fix _datetime.fromisoformat() mishandling a sub-second tz offset (#152087)
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-25 10:15:28 +01:00
stevens
05225aa06a
gh-151126: Fix missing memory errors in _interpretersmodule.c (#151624) 2026-06-25 12:02:00 +03:00
sobolevn
a6c2d4ae3b
gh-151763: Fix crash in _interpqueues.create on MemoryError (#152131) 2026-06-25 07:04:02 +00:00
Serhiy Storchaka
a52f428fba
gh-151776: Add curses state-query functions (GH-151778)
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>
2026-06-24 22:31:50 +03:00
Serhiy Storchaka
3cd4283ba6
gh-151774: Add curses dynamic color-pair functions (GH-151775)
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>
2026-06-24 21:24:11 +03:00
Zain Nadeem
ce8b81fff4
gh-151763: Fix NULL dereference in os._path_normpath() under OOM (#151779) 2026-06-24 16:56:10 +01:00
Stan Ulbrych
15696a69d6
gh-90949: Fix copy-paste typo in pyexpat capsule API initialization (#151147) 2026-06-24 15:10:46 +01:00
Timofei
ad2cabfccb
gh-152020: Fix asyncio.all_tasks() loosing eager tasks on FT-build (#152022)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-06-24 17:51:42 +05:30
Stan Ulbrych
c61307222e
gh-151814: Fix unbounded memory growth from repeated empty writes to io.TextIOWrapper (#151817) 2026-06-24 12:47:52 +01:00
Serhiy Storchaka
ac023ea48f
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>
2026-06-24 11:33:02 +00:00
Serhiy Storchaka
560ff8e202
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>
2026-06-24 06:08:34 +00:00
Serhiy Storchaka
124c7cd91b
gh-126219: Fix crash in tkinter.Tk with non-BMP className on Tcl/Tk 8.x (GH-151980)
Tcl 8.x crashes when title-casing a non-BMP character during Tk
initialization, so such a className is now rejected with a ValueError.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 08:59:42 +03:00
Serhiy Storchaka
a5677bff84
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>
2026-06-24 08:52:10 +03:00
Serhiy Storchaka
fde4cf862c
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>
2026-06-24 08:49:14 +03:00
Amrutha
5e0747db2f
gh-151842: Fix crash upon OOM in _interpreters.capture_exception (GH-151843) 2026-06-23 16:31:47 -04:00
Ivy Xu
4448205d95
gh-151126: Fix missing PyErr_NoMemory in getpath.c (#151590) 2026-06-22 14:59:22 +01:00
tonghuaroot (童话)
1fb874cc07
gh-151770: Fix datetime.fromisoformat() on an out-of-range month w/ a 24:00 time (#151771)
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-20 17:33:16 +01:00
Serhiy Storchaka
2e5843e13f
gh-151744: Add curses.nofilter() (GH-151747)
Wrap the ncurses nofilter() function, which undoes the effect of
filter().  Without it there is no way to restore normal screen sizing
after a curses.filter() call in the same process.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 17:49:26 +00:00
Jonathan J. Helmus
c4eb3adbb4
gh-150836: Mount embedded Tk ZIP in _tkinter on Windows (GH-151562)
Tcl/Tk 9 may embed the Tk script library in the Tk DLL on Windows. This embedded library is not found by Tcl by default.

Mount the loaded Tk DLL as a zipfs archive before calling Tk_Init(), so Tk can find its embedded tk_library using its existing library discovery logic.

Preserve Tk_Init()'s normal path if the library is not embedded.
2026-06-19 14:23:01 +00:00
Serhiy Storchaka
551f8e16f8
gh-151695: Fix use-after-free of the curses screen encoding (GH-151696)
The module-global curses_screen_encoding stored a borrowed pointer to the
encoding owned by the window returned by the first initscr() call.  That
window can be deallocated while unctrl() and ungetch(), which have no window
of their own, still use the pointer to encode non-ASCII characters.

Keep a private copy of the encoding instead.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 08:38:15 +00:00
Mark Shannon
ad1513a263
GH-150516: Reduce the work done to spill and reload the stack around calls (GH-151587) 2026-06-18 15:14:30 +01:00
Donghee Na
3fa92e7c55
gh-151229: Finalize JIT tracer in test eval-frame stub (gh-151609) 2026-06-18 20:58:12 +09:00
Serhiy Storchaka
12add3822f
gh-151623: Add missing curses docstrings and document intrflush() (#151632) 2026-06-18 13:52:26 +03:00
Serhiy Storchaka
65afcdd8df
gh-151623: Improve curses documentation and docstrings (GH-151625)
Fix errors and clarify the curses, curses.panel and curses.ascii docs
against X/Open Curses and ncurses, and sync the affected docstrings.
2026-06-18 11:20:03 +03:00
Donghee Na
8d7c6dcde0
gh-150942: Optimize PicklerMemoProxy.copy() with _PyDict_SetItem_Take2 (gh-151608) 2026-06-18 09:08:00 +09:00
Maurycy Pawłowski-Wieroński
a8d74c062f
gh-151436: Fix missing tstate->last_profiled_frame updates (#151437) 2026-06-17 16:49:23 -04:00
AN Long
eff805b7a7
gh-151510: Fix __lazy_import__ without frame (#151511) 2026-06-17 14:09:51 -04:00
Petr Viktorin
16185e9fe2
gh-149044: Improve Py_tp_base[s] docs & error message for non-type bases (GH-151252)
The initial implementation of PEP 820 worsened the error message
when non-types are given as base types in Py_tp_bases & Py_tp_base.
Bring back the 'bases must be types' wording and add a 'got' note for
easier debugging.

Improve slot ID documentation, and soft-deprecate Py_tp_base
(as per the PEP).
2026-06-17 15:27:02 +02:00
sobolevn
a173a6d65b
gh-151584: Remove PyUnstable_Module_SetGIL call in _remote_debugging (#151585) 2026-06-17 15:37:08 +03:00
Steve Dower
9e863fab28
gh-151544: Fixes CVE-2026-12003 by removing the fallback to %VPATH%/Modules/Setup.local for discovering sources in getpath.py (GH-151545) 2026-06-17 00:16:06 +01:00