Skip to content

curses: remove ncurses assumptions from the module and its tests #154934

Closed

Description

@serhiy-storchaka

Bug report

The curses module and its tests assume in several places that the library behind them is ncurses.

PyCurses_ConvertToChtype() and PyCurses_ConvertToCchar_t() parse the integer forms of addch() and friends through a signed long, and attr_converter() through an unsigned long. The width of a chtype is up to the library: with a 64-bit one, addch(ord('A') | curses.color_pair(589823)) fails with OverflowError. Parsing as unsigned long long fixes it and changes nothing for a narrower chtype.

test_curses decides what a cell can hold by probing for a function, and assumes throughout that the integer form of a character is its locale byte and that inch() returns that byte. Exposing whether the module was built for wide characters (_curses._wide_character_support) lets it ask directly.

Textbox._decode() masks an integer keystroke with A_CHARTEXT, which is the character field of a cell rather than a byte, and _printable_key() calls anything up to 0xff printable although key codes need not start above a byte.

None of this changes behaviour on ncurses, where chtype is 32 bits, A_CHARTEXT is 0xff and KEY_MIN is above a byte. It is the part of gh-85796 that is not specific to PDCurses.

Linked PRs

Activity

  1. added a commit that references this issue on Jul 30, 2026
  2. added a commit that references this issue on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions