Title: Add escaping mode to PyUnicode_FromFormat(): %#c, %#s, %#S, %#U, %#V · Issue #154668 · python/cpython · GitHub
Open Graph Title: Add escaping mode to PyUnicode_FromFormat(): %#c, %#s, %#S, %#U, %#V · Issue #154668 · python/cpython
X Title: Add escaping mode to PyUnicode_FromFormat(): %#c, %#s, %#S, %#U, %#V · Issue #154668 · python/cpython
Description: Feature or enhancement Error messages often embed a C string or an object via the s, S, U and V conversions in PyUnicode_FromFormat() and PyErr_Format(). If the string contains non-printable characters, the message can be mangled or misl...
Open Graph Description: Feature or enhancement Error messages often embed a C string or an object via the s, S, U and V conversions in PyUnicode_FromFormat() and PyErr_Format(). If the string contains non-printable charac...
X Description: Feature or enhancement Error messages often embed a C string or an object via the s, S, U and V conversions in PyUnicode_FromFormat() and PyErr_Format(). If the string contains non-printable charac...
Opengraph URL: https://github.com/python/cpython/issues/154668
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add escaping mode to PyUnicode_FromFormat(): %#c, %#s, %#S, %#U, %#V","articleBody":"# Feature or enhancement\n\nError messages often embed a C string or an object via the `s`, `S`, `U` and `V` conversions in `PyUnicode_FromFormat()` and `PyErr_Format()`. If the string contains non-printable characters, the message can be mangled or misleading: embedded newlines and terminal escape sequences break the output, invisible characters hide the actual content. The `R` and `A` conversions escape, but add surrounding quotes and require a Python object.\n\nI propose to add an escaping mode, enabled by the `#` flag for the `c`, `s`, `S`, `U` and `V` conversions. It escapes special and non-printable characters like `repr()` does, but without adding quotes: `\\\\`, `\\t`, `\\r` and `\\n`; other non-printable ASCII characters as `\\xNN`; other non-printable characters as `\\uNNNN` or `\\UNNNNNNNN`. With the additional `+` flag (`%+#s`), all non-ASCII characters are escaped as well, so the result is pure ASCII.\n\nFor the `s` and `V` conversions, bytes which cannot be decoded from UTF-8 are escaped as `\\xNN`, while valid non-ASCII characters are always escaped as `\\uNNNN` or `\\UNNNNNNNN` (e.g. `\\u009f` for valid `\\xc2\\x9f`), so they can always be distinguished.\n\nThe precision is applied to the string before escaping, the width -- after escaping.\n\nQuotes are deliberately not escaped: the escaped string is intended to be embedded into a larger message without quotes. For quoted output use the `R` and `A` conversions.\n\nRelated: gh-154610 (escaping attribute names in `AttributeError` messages).\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154669\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2026-07-25T04:36:55Z","url":"https://github.com/python/cpython/issues/154668"}
| 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:b46fb087-f5ac-10fc-c97a-aa252d567c6c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B716:1AE20C:45A883F:580FB51:6B022C30 |
| html-safe-nonce | 5c7e89384fbb336b828610ccf3ab7b54cba55659b14f7590e35442ffa0a93889 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzE2OjFBRTIwQzo0NUE4ODNGOjU4MEZCNTE6NkIwMjJDMzAiLCJ2aXNpdG9yX2lkIjoiNDc5NDM2MjIzMTExMzc1OTIwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2b39f8691e931f3aa6164d3e813490a9682f1b322a8d41820daef427d6753c48 |
| hovercard-subject-tag | issue:4974180833 |
| 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/154668/issue_layout |
| twitter:image | https://opengraph.githubassets.com/74ec383b70184ac6e6a6a600edd39012602ba921b74e38ed2839a6669a1935cb/python/cpython/issues/154668 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/74ec383b70184ac6e6a6a600edd39012602ba921b74e38ed2839a6669a1935cb/python/cpython/issues/154668 |
| og:image:alt | Feature or enhancement Error messages often embed a C string or an object via the s, S, U and V conversions in PyUnicode_FromFormat() and PyErr_Format(). If the string contains non-printable charac... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | serhiy-storchaka |
| 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