Title: curses `window.encoding` does not encode `str` arguments on a wide build · Issue #156347 · python/cpython · GitHub
Open Graph Title: curses `window.encoding` does not encode `str` arguments on a wide build · Issue #156347 · python/cpython
X Title: curses `window.encoding` does not encode `str` arguments on a wide build · Issue #156347 · python/cpython
Description: Documentation The curses HOWTO says that strings passed to window.addstr() are "encoded to bytes using the value of the window's encoding attribute", and the window.encoding entry in the library reference describes it as the "Encoding us...
Open Graph Description: Documentation The curses HOWTO says that strings passed to window.addstr() are "encoded to bytes using the value of the window's encoding attribute", and the window.encoding entry in the library re...
X Description: Documentation The curses HOWTO says that strings passed to window.addstr() are "encoded to bytes using the value of the window's encoding attribute", and the window.encoding entry in ...
Opengraph URL: https://github.com/python/cpython/issues/156347
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"curses `window.encoding` does not encode `str` arguments on a wide build","articleBody":"### Documentation\n\nThe curses HOWTO says that strings passed to `window.addstr()` are \"encoded to bytes using the value of the window's `encoding` attribute\", and the `window.encoding` entry in the library reference describes it as the \"Encoding used to encode method arguments (Unicode strings and characters)\". On a build linked against a wide-character version of the curses library, which is what CPython configures by default, neither is true: `PyCurses_ConvertToString` in `Modules/_cursesmodule.c` converts `str` with `PyUnicode_AsWideCharString` and never reads `win->encoding`, so the bytes that reach the terminal come from the current locale instead.\n\n```python\nimport curses, os, pty, sys\n_, slave = pty.openpty()\nos.dup2(slave, 0); os.dup2(slave, 1)\nwin = curses.initscr()\nwin.encoding = 'latin-1'\nwin.addstr(0, 0, 'caf\\xe9')\ngot = win.instr(0, 0, 6)\ncurses.endwin()\nprint('stored:', got, ' latin-1 would be:', 'caf\\xe9'.encode('latin-1'), file=sys.stderr)\n```\n\n```\nstored: b'caf\\xc3\\xa9 ' latin-1 would be: b'caf\\xe9'\n```\n\nExpected: `b'caf\\xe9'`, the bytes `latin-1` produces, if `window.encoding` were used to encode the argument.\n\nThe attribute is used on a narrow build, where it also decodes results, so the correction has to name the build rather than call the attribute unused.\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-156352\n* gh-156354\n* gh-156872\n* gh-156873\n* gh-156874\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/fedonman","@type":"Person","name":"fedonman"},"datePublished":"2026-08-25T08:20:49Z","url":"https://github.com/python/cpython/issues/156347"}
| 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:75f5219d-d4ad-2371-f167-5fb581440844 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 82E2:24645:14DA93D:1B86CF4:6B01F761 |
| html-safe-nonce | b3ee122c4c7f3a401c150b9f9b99bc9a51def8fa5c7cc8f477195dfcd1a0da9f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkUyOjI0NjQ1OjE0REE5M0Q6MUI4NkNGNDo2QjAxRjc2MSIsInZpc2l0b3JfaWQiOiI1NTY4NDIxNTk1MzQzNzI3MDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0e9adccf78d4686ef27be599124c2a86c6db1f7c17246a0f395638d116102989 |
| hovercard-subject-tag | issue:5243633154 |
| 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/156347/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3c987248f8fb1872f1960093fe5936854bd0336dbeea3fba93d8c0d64ab36d6a/python/cpython/issues/156347 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3c987248f8fb1872f1960093fe5936854bd0336dbeea3fba93d8c0d64ab36d6a/python/cpython/issues/156347 |
| og:image:alt | Documentation The curses HOWTO says that strings passed to window.addstr() are "encoded to bytes using the value of the window's encoding attribute", and the window.encoding entry in the library re... |
| 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 | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width