Skip to content

gh-154874: Fix the sign of curses.termattrs() - #154875

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
fedonman:fix-curses-termattrs-sign
Jul 30, 2026
Merged

gh-154874: Fix the sign of curses.termattrs()#154875
serhiy-storchaka merged 1 commit into
python:mainfrom
fedonman:fix-curses-termattrs-sign

Conversation

@fedonman

@fedonman fedonman commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

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

>>> curses.termattrs()
-2130771968
>>> curses.term_attrs()          # the same bits, unsigned
2164195328
>>> curses.newwin(1, 1).attrset(curses.termattrs())
OverflowError: can't convert negative value to unsigned int

It now returns the mask unsigned, the same way getattrs(), slk_attr() and
term_attrs() already do. baudrate(), the macro's only other user, really does return
a status, so it keeps the ERR check.

The test drives newterm('xterm-256color') over a pseudo-terminal rather than using
$TERM, which on CI is usually linux and advertises no italic, so a signed result
would slip through. It fails without the change.

3.15 has the same bug, so this needs a backport. 3.14 is fine.

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.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) July 30, 2026 19:49
@serhiy-storchaka
serhiy-storchaka merged commit 0b083c4 into python:main Jul 30, 2026
59 checks passed
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 30, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @fedonman for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @fedonman for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @fedonman for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app

Copy link
Copy Markdown

Sorry, @fedonman and @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 0b083c43a455fbdf5378495751e142ea83e294b0 3.13

@miss-islington-app

Copy link
Copy Markdown

Sorry, @fedonman and @serhiy-storchaka, I could not cleanly backport this to 3.15 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 0b083c43a455fbdf5378495751e142ea83e294b0 3.15

@miss-islington-app

Copy link
Copy Markdown

Sorry, @fedonman and @serhiy-storchaka, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 0b083c43a455fbdf5378495751e142ea83e294b0 3.14

@serhiy-storchaka serhiy-storchaka removed needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants