Title: gh-154874: Fix curses.termattrs() returning a negative attribute mask by mandarwagh9 · Pull Request #154887 · python/cpython · GitHub
Open Graph Title: gh-154874: Fix curses.termattrs() returning a negative attribute mask by mandarwagh9 · Pull Request #154887 · python/cpython
X Title: gh-154874: Fix curses.termattrs() returning a negative attribute mask by mandarwagh9 · Pull Request #154887 · python/cpython
Description: termattrs() returns a chtype attribute mask, but GH-134327 routed it through NoArgReturnIntFunctionBody, which stores the result in an int so it can be compared against ERR. On a terminal that advertises A_ITALIC — the topmost bit of a 32-bit mask — that sign-extends, and the mask comes back negative: >>> 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 The value is now returned unsigned, the same way term_attrs(), slk_attr() and window.getattrs() already do. The cast goes through chtype rather than straight to unsigned long, matching getattrs(), so no sign extension can happen on a platform that declares termattrs() as returning an int. baudrate() is the macro's only other user and really does return a status, so it keeps the ERR check. The macro gains a short comment saying it is only for such functions — the same mistake is easy to repeat, and an all-bits-set mask would additionally be misread as ERR. Test TermAttrsTests drives newterm('xterm-256color') over a pseudo-terminal rather than relying on $TERM, which on CI is usually linux and advertises no italic. Its two assertions hold on any terminal, so it never skips for lack of an italic-capable one; it fails without the C change wherever the top bit is actually advertised. Backport git branch -r --contains 30dde1ee (the GH-134327 merge) gives main and 3.15 only, so this needs a 3.15 backport and nothing older. 3.14 is unaffected. The issue carries 3.14 and 3.16 labels as well, but 3.14 predates the regression. Notes gh-154875 proposes the same one-line fix; I opened this independently and only saw it afterwards. Happy for whichever is more useful to maintainers to land — closing this one is completely fine. I could not build or run _curses locally (Windows), so the test here is unverified by me and I am relying on CI to run it. Worth a careful look on that account. Prepared with AI assistance (Claude); the reasoning and the diff have been reviewed by me, but please weigh the point above accordingly. Issue: gh-154874
Open Graph Description: termattrs() returns a chtype attribute mask, but GH-134327 routed it through NoArgReturnIntFunctionBody, which stores the result in an int so it can be compared against ERR. On a terminal that adve...
X Description: termattrs() returns a chtype attribute mask, but GH-134327 routed it through NoArgReturnIntFunctionBody, which stores the result in an int so it can be compared against ERR. On a terminal that adve...
Opengraph URL: https://github.com/python/cpython/pull/154887
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:e31f898c-ecf8-e709-7580-70ac42e1cfaf |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D0B0:93BED:D79921:1248CF0:6B064E48 |
| html-safe-nonce | 8f924c5182c8106e0c1b7f923bda87c8e7656dc2a0a6e26ffea1e3909c7f8326 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMEIwOjkzQkVEOkQ3OTkyMToxMjQ4Q0YwOjZCMDY0RTQ4IiwidmlzaXRvcl9pZCI6IjMyNzYyMzg0OTQ0MTQyOTQ2MDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d7c55c8db7d86ab06299261d838445ad7cb2e5f8cf9c776c22fbf9804c9563ce |
| hovercard-subject-tag | pull_request:4162397684 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/python/cpython/pull/154887/files |
| twitter:image | https://avatars.githubusercontent.com/u/169690780?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/169690780?s=400&v=4 |
| og:image:alt | termattrs() returns a chtype attribute mask, but GH-134327 routed it through NoArgReturnIntFunctionBody, which stores the result in an int so it can be compared against ERR. On a terminal that adve... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f1f9a08f7c769a37f1dfc18ad43d463c222a7eea |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width