Skip to content

gh-154934: Remove ncurses assumptions from curses and its tests - #154940

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:curses-portability
Jul 30, 2026
Merged

gh-154934: Remove ncurses assumptions from curses and its tests#154940
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:curses-portability

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

The integer forms of addch() and friends were parsed through a signed long, attributes through an unsigned long, and the slk_attr*() functions took an int or a long; they now use unsigned long long and attr_t, the width of a chtype being up to the library. With a 64-bit one, addch(ord('A') | curses.color_pair(589823)) no longer raises OverflowError.

test_curses decided whether cells hold wide characters by probing for a function; _curses._wide_character_support reports what the module was built for. A _char_code() helper gives the integer a character is written as, replacing the same encode-and-check written out in six tests.

Textbox._decode() masked an integer keystroke with A_CHARTEXT, which is a byte only where a cell holds one, and _printable_key() treated everything up to 0xff as printable although key codes may start below that.

Nothing changes on ncurses, where a chtype is 32 bits, A_CHARTEXT is 0xff and KEY_MIN is above a byte. test_curses passes there in C.utf8, uk_UA.koi8u and en_US.iso885915, and against PDCursesMod in five configurations (wide and narrow, 32- and 64-bit chtype, forced UTF-8), of which the 64-bit ones exercise the widening.

Parse the integer forms of addch() and friends as unsigned long long: the
width of a chtype is up to the library.

Expose _curses._wide_character_support so that the tests can ask what a
cell holds instead of probing for a function.

Mask an integer keystroke in textpad as the byte it is, and keep the key
codes out of the printable range.
@serhiy-storchaka
serhiy-storchaka merged commit 9ef95d1 into python:main Jul 30, 2026
54 checks passed
@serhiy-storchaka
serhiy-storchaka deleted the curses-portability branch July 30, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant