Skip to content

[3.15] gh-155974: Restore the window attributes when a curses write fails (GH-155975) - #156136

Merged
hugovk merged 2 commits into
python:3.15from
miss-islington:backport-83531fd-3.15
Aug 29, 2026
Merged

[3.15] gh-155974: Restore the window attributes when a curses write fails (GH-155975)#156136
hugovk merged 2 commits into
python:3.15from
miss-islington:backport-83531fd-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

addstr(), addnstr(), insstr() and insnstr() set the window rendition to
the caller's attr, write, then restore the previous rendition. Since
30dde1e the restore sits below an early return taken when the write
fails, so a failed write leaves the caller's attr on the window and
drops whatever the application had set with attrset().

Restore the rendition first and report the write error afterwards. A
wattrset() failure is still reported when the write itself succeeded.
(cherry picked from commit 83531fd)

Co-authored-by: Vyron Vasileiadis hi@fedonman.com

…ils (pythonGH-155975)

addstr(), addnstr(), insstr() and insnstr() set the window rendition to
the caller's attr, write, then restore the previous rendition.  Since
30dde1e the restore sits below an early return taken when the write
fails, so a failed write leaves the caller's attr on the window and
drops whatever the application had set with attrset().

Restore the rendition first and report the write error afterwards.  A
wattrset() failure is still reported when the write itself succeeded.
(cherry picked from commit 83531fd)

Co-authored-by: Vyron Vasileiadis <hi@fedonman.com>
@hugovk

hugovk commented Aug 29, 2026

Copy link
Copy Markdown
Member

@fedonman @serhiy-storchaka This has lots of test failures like:

ERROR: test_output_string_attr_restored (test.test_curses.TestCurses.test_output_string_attr_restored) [window.addstr]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/runner/work/cpython/cpython/Lib/test/test_curses.py", line 445, in test_output_string_attr_restored
    self.assertEqual(win.getattrs(), curses.A_UNDERLINE)
                     ^^^^^^^^^^^^
AttributeError: '_curses.window' object has no attribute 'getattrs'

window.getattrs() is new in 3.16.  Write a cell with the window's current
rendition and read it back with inch() instead.
@serhiy-storchaka

Copy link
Copy Markdown
Member

window.getattrs() is new in 3.16. I fixed the test by using indirect method -- writing something with default attributes, and then reading back what was written. I tested -- the test serves its purpose, it fails with non-fixed code and passes with fixed code.

@serhiy-storchaka

Copy link
Copy Markdown
Member

Don't forget to edit the commit message before merging and remove the second commit.

@hugovk
hugovk merged commit 68a0f7e into python:3.15 Aug 29, 2026
54 checks passed
@miss-islington
miss-islington deleted the backport-83531fd-3.15 branch August 29, 2026 14:50
@hugovk

hugovk commented Aug 29, 2026

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants