Skip to content

gh-157710: Soft deprecate C API modifying str objects - #157711

Open
vstinner wants to merge 5 commits into
python:mainfrom
vstinner:deprecate_unicode_capi
Open

vstinner wants to merge 5 commits into
python:mainfrom
vstinner:deprecate_unicode_capi

Conversation

@vstinner

@vstinner vstinner commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Soft deprecate PyUnicode_New(), PyUnicode_CopyCharacters(), PyUnicode_Fill(), PyUnicode_Resize(), PyUnicode_WRITE() and PyUnicode_WriteChar() functions. Use the PyUnicodeWriter API instead.

Soft deprecate PyUnicode_New(), PyUnicode_CopyCharacters(),
PyUnicode_Fill(), PyUnicode_Resize(), PyUnicode_WRITE() and
PyUnicode_WriteChar() functions. Use the PyUnicodeWriter API instead.

Mention also that PyUnicodeWriter is not thread safe.
@vstinner

Copy link
Copy Markdown
Member Author

@read-the-docs-community

read-the-docs-community Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34906781 | 📁 Comparing 7b69414 against main (5539c2a)

  🔍 Preview build  

49 files changed · + 1 added · ± 48 modified

+ Added

± Modified

@encukou

encukou commented Sep 18, 2026

Copy link
Copy Markdown
Member

It looks like this should be a WG decision. I'd vote for it though.

@vstinner

Copy link
Copy Markdown
Member Author

@encukou:

It looks like this should be a WG decision. I'd vote for it though.

Ok. I created capi-workgroup/decisions#111 to get a decision from the C API Working Group. I added more details: list of PyPI affected project and mention that pythoncapi-compat provides the PyUnicodeWriter API on Python 3.6-3.13.

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 2, 2026
test_capi.test_unicode:

* Add tests on PyUnicode_New() and PyUnicode_Resize(). Check that the
  result is either a mutable string, or the empty string singleton.
* Check that PyUnicode_Fill(), PyUnicode_CopyCharacters() and
  PyUnicode_WriteChar() fail to modify a string with 2 references.

Adjust documentation.
@vstinner
vstinner enabled auto-merge (squash) October 2, 2026 20:33
@vstinner

vstinner commented Oct 2, 2026

Copy link
Copy Markdown
Member Author

The C API Working Group approved the soft deprecation: capi-workgroup/decisions#111 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review docs Documentation in the Doc dir type-feature A feature request or enhancement

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants