Title: C API: Add PyUnicodeWriter_WriteRawStr() function · Issue #150973 · python/cpython · GitHub
Open Graph Title: C API: Add PyUnicodeWriter_WriteRawStr() function · Issue #150973 · python/cpython
X Title: C API: Add PyUnicodeWriter_WriteRawStr() function · Issue #150973 · python/cpython
Description: Feature or enhancement Python 3.14 added PyUnicodeWriter_WriteStr() function. In general, writing str(obj) is fine. But there is one exception: writing a str subclass should not call str(obj), otherwise the output can be surprising if th...
Open Graph Description: Feature or enhancement Python 3.14 added PyUnicodeWriter_WriteStr() function. In general, writing str(obj) is fine. But there is one exception: writing a str subclass should not call str(obj), othe...
X Description: Feature or enhancement Python 3.14 added PyUnicodeWriter_WriteStr() function. In general, writing str(obj) is fine. But there is one exception: writing a str subclass should not call str(obj), othe...
Opengraph URL: https://github.com/python/cpython/issues/150973
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"C API: Add PyUnicodeWriter_WriteRawStr() function","articleBody":"# Feature or enhancement\n\nPython 3.14 added [PyUnicodeWriter_WriteStr() function](https://docs.python.org/dev/c-api/unicode.html#c.PyUnicodeWriter_WriteStr). In general, writing `str(obj)` is fine. But there is one exception: writing a `str` subclass should not call `str(obj)`, otherwise the output can be surprising if the subclass overrides `__str__()`.\n\nThe `_json` and `_io` were impacted by the `str` subclass issue. They have been fixed by using the internal C API (`_PyUnicodeWriter_WriteStr()`). Problem: the internal C API is not usable outside CPython.\n\nThe PyUnicodeWriter_WriteStr() documentation has been modified to document a workaround for `str` subclasses:\n\n\u003e To write a `str` subclass which overrides the `__str__()` method, `PyUnicode_FromObject()` can be used to get the original string.\n\nInstead of the workaround, I propose adding a `PyUnicodeWriter_WriteRawStr()` function which handles `str` subclasses as expected (read the string content, don't use the `__str__()` method).\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-150974\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/vstinner","@type":"Person","name":"vstinner"},"datePublished":"2026-06-05T14:53:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/150973/cpython/issues/150973"}
| 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:8e6eec62-109f-4e33-85c2-0553a3b6f567 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E5CE:193F03:C656EA:1128B15:6A4DC9E8 |
| html-safe-nonce | 756a0070e066a8f886bfae21aa7a8a3705a4d906ead9264fd387196a1ad79e10 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNUNFOjE5M0YwMzpDNjU2RUE6MTEyOEIxNTo2QTREQzlFOCIsInZpc2l0b3JfaWQiOiI0NzYzODk3MjkwMzU5MTYzMzY4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 5276a2a130a42debcb09a969f665c24fdf134d8b2d590ebb47e6770b9e0146f3 |
| hovercard-subject-tag | issue:4597846313 |
| 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/150973/issue_layout |
| twitter:image | https://opengraph.githubassets.com/13d036361020b1fa6a401c5e75435f32fae187a4a4db8ed6116a3933cb99df3e/python/cpython/issues/150973 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/13d036361020b1fa6a401c5e75435f32fae187a4a4db8ed6116a3933cb99df3e/python/cpython/issues/150973 |
| og:image:alt | Feature or enhancement Python 3.14 added PyUnicodeWriter_WriteStr() function. In general, writing str(obj) is fine. But there is one exception: writing a str subclass should not call str(obj), othe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vstinner |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| 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 | 1d344bdb7547fe6bca17a59bb2b8aac3dc9532a0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width