Title: curses.termattrs() returns a negative value on italic terminals · Issue #154874 · python/cpython · GitHub
Open Graph Title: curses.termattrs() returns a negative value on italic terminals · Issue #154874 · python/cpython
X Title: curses.termattrs() returns a negative value on italic terminals · Issue #154874 · python/cpython
Description: Bug description: curses.termattrs() returns a negative value on a terminal that advertises A_ITALIC (bit 31), so its result cannot be passed back to the attribute functions: >>> curses.termattrs() -2130771968 >>> curses.term_attrs() # th...
Open Graph Description: Bug description: curses.termattrs() returns a negative value on a terminal that advertises A_ITALIC (bit 31), so its result cannot be passed back to the attribute functions: >>> curses.termattrs() ...
X Description: Bug description: curses.termattrs() returns a negative value on a terminal that advertises A_ITALIC (bit 31), so its result cannot be passed back to the attribute functions: >>> curses.ter...
Opengraph URL: https://github.com/python/cpython/issues/154874
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"curses.termattrs() returns a negative value on italic terminals","articleBody":"### Bug description:\n\n`curses.termattrs()` returns a negative value on a terminal that advertises `A_ITALIC` (bit 31), so its result cannot be passed back to the attribute functions:\n\n```\n>>> curses.termattrs()\n-2130771968\n>>> curses.term_attrs() # the same bits, unsigned\n2164195328\n>>> curses.newwin(1, 1).attrset(curses.termattrs())\nOverflowError: can't convert negative value to unsigned int\n```\n\nThis is a regression in 3.15. Up to 3.14 the macro behind it returned `PyLong_FromLong((long) X())`, and on a 64-bit `long` the mask stayed positive. GH-134327 rewrote it to check for `ERR` through an `int`, which sign-extends:\n\n```c\n int rtn = X();\n if (rtn == ERR) { ... }\n return PyLong_FromLong(rtn);\n```\n\n`ERR` checking is right for `baudrate()`, the macro's only other user, but `termattrs()` returns a `chtype` mask, not a status. `term_attrs()`, `slk_attr()` and `window.getattrs()` all return theirs with `PyLong_FromUnsignedLong`.\n\n### CPython versions tested on:\n\nCPython main branch, 3.14\n\n### Operating systems tested on:\n\nLinux\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154875\n* gh-154887\n* gh-155548\n* gh-162542\n\u003c!-- /gh-linked-prs -->\n\n","author":{"url":"https://github.com/fedonman","@type":"Person","name":"fedonman"},"datePublished":"2026-07-29T11:48:56Z","url":"https://github.com/python/cpython/issues/154874"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:406dfffa-199b-2864-5bdf-3da9f675cd5b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C302:20398C:CEFEDA:118CF70:6B064BBD |
| html-safe-nonce | 8ce6ec588ca52385731bf8a7f0989a9210891cf4f7c0f473952fa47154e7ccad |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzAyOjIwMzk4QzpDRUZFREE6MTE4Q0Y3MDo2QjA2NEJCRCIsInZpc2l0b3JfaWQiOiIxODYxMTkwMDM3NjA2Mzg2NjIxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4fcdf0518afc62fd786329fd5be035c2acf2a3ea58f86ffc3fca0b2c5a7c8f74 |
| hovercard-subject-tag | issue:5008874768 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/154874/issue_layout |
| twitter:image | https://opengraph.githubassets.com/39f8bdf1fe52cb2242d5ca0cd57a8899923672401ecdd87c2ef34d693dcf7582/python/cpython/issues/154874 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/39f8bdf1fe52cb2242d5ca0cd57a8899923672401ecdd87c2ef34d693dcf7582/python/cpython/issues/154874 |
| og:image:alt | Bug description: curses.termattrs() returns a negative value on a terminal that advertises A_ITALIC (bit 31), so its result cannot be passed back to the attribute functions: >>> curses.termattrs() ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fedonman |
| hostname | github.com |
| expected-hostname | github.com |
| None | 772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f1f9a08f7c769a37f1dfc18ad43d463c222a7eea |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width