Skip to content

[3.15] gh-154874: Fix the sign of curses.termattrs() (GH-154875) - #155548

Open
sankalpsthakur wants to merge 1 commit into
python:3.15from
sankalpsthakur:fix/154874-termattrs-backport-3.15
Open

[3.15] gh-154874: Fix the sign of curses.termattrs() (GH-154875)#155548
sankalpsthakur wants to merge 1 commit into
python:3.15from
sankalpsthakur:fix/154874-termattrs-backport-3.15

Conversation

@sankalpsthakur

Copy link
Copy Markdown

Summary

Backport of GH-154875 to 3.15.

curses.termattrs() returns a chtype mask, but it was routed through an int to check for ERR. On a terminal that advertises A_ITALIC (topmost bit of a 32-bit mask), the result came back negative and the attribute functions rejected it:

>>> curses.termattrs()
-2130771968
>>> curses.newwin(1, 1).attrset(curses.termattrs())
OverflowError: can't convert negative value to unsigned int

This returns the mask unsigned via PyLong_FromUnsignedLong, matching getattrs(), slk_attr(), and term_attrs().

The main-branch regression test uses newterm() over a pseudo-terminal (NewtermTestBase), which is not present on 3.15. The 3.15 test is adapted onto TestCurses and skips when the current terminal does not advertise a top-bit attribute.

(cherry picked from commit 0b083c4)

Fixes #154874

Test plan

  • CI: test_curses (requires curses resource)
  • Local: full CPython rebuild not run in this environment; change matches main fix in Modules/_cursesmodule.c and includes NEWS + adapted unit test.

AI/LLM disclosure

  • AI coding tools (including Grok and/or Codex agent-assisted editing) were used to help draft or modify code and this PR description.
  • I reviewed the complete change, understand the reasoning, and ran the reported local tests before submitting.
  • This submission is original work of authorship under the project CLA / contributor terms; AI output was not pasted unreviewed.

Made with Cursor

…154875)

termattrs() returns a chtype mask, but it was routed through an int, so a
terminal that advertises A_ITALIC came back negative and the result could
no longer be passed to the attribute functions.

(cherry picked from commit 0b083c4)

Co-authored-by: Vyron Vasileiadis <hi@fedonman.com>
Signed-off-by: Sankalp Thakur <sankalphimself@gmail.com>
@sankalpsthakur
sankalpsthakur force-pushed the fix/154874-termattrs-backport-3.15 branch from e5cf968 to 225795a Compare August 11, 2026 09:47
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.

2 participants