-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
PEP 623: Remove wstr from Unicode object #1462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5aa24c6
New PEP: Remove wstr from Unicode object
methane 92ad1e7
Simplify the proposal
methane 9c29409
Add rationale section
methane 9f4ac5c
PEP 629
methane 65bd851
update
methane 6728abc
add parens
methane 3867f0e
PEP 623
methane 6a9ba2b
fix typo
methane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| PEP: 623 | ||
| Title: Remove wstr from Unicode | ||
| Author: Inada Naoki <songofacandy@gmail.com> | ||
| Status: Draft | ||
| Type: Standards Track | ||
| Content-Type: text/x-rst | ||
| Created: 25-Jun-2020 | ||
| Python-Version: 3.10 | ||
|
|
||
|
|
||
| Abstract | ||
| ======== | ||
|
|
||
| PEP 393 deprecated some unicode APIs, and introduced ``wchar_t *wstr``, | ||
| and ``Py_ssize_t wstr_length`` in the Unicode structure to support | ||
| these deprecated APIs. [1]_ | ||
|
|
||
| This PEP is planning removal of ``wstr``, and ``wstr_length`` with | ||
| deprecated APIs using these members by Python 3.12. | ||
|
|
||
| Deprecated APIs which doesn't use the members are out of scope because | ||
| they can be removed independently. | ||
|
|
||
|
|
||
| Motivation | ||
| ========== | ||
|
|
||
| Memory usage | ||
| ------------ | ||
|
|
||
| ``str`` is one of the most used types in Python. Even most simple ASCII | ||
| strings have a ``wstr`` member. It consumes 8 bytes on 64bit systems. | ||
|
|
||
|
|
||
| Runtime overhead | ||
| ---------------- | ||
|
|
||
| To support legacy Unicode object created by | ||
| ``PyUnicode_FromUnicode(NULL, length)``, many Unicode APIs has | ||
| ``PyUnicode_READY()`` check. | ||
|
|
||
| When we drop support of legacy unicode object, We can reduce this | ||
| overhead too. | ||
|
|
||
|
|
||
| Simplicity | ||
| ---------- | ||
|
|
||
| Support of legacy Unicode object makes Unicode implementation complex. | ||
| Until we drop legacy Unicode object, it is very hard to try other | ||
| Unicode implementation like UTF-8 based implementation in PyPy. | ||
|
|
||
|
|
||
| Rationale | ||
| ========= | ||
|
|
||
| Python 4.0 is not scheduled yet | ||
| ------------------------------- | ||
|
|
||
| PEP 393 introduced efficient internal representation of Unicode and | ||
| removed border between "narrow" and "wide" build of Python. | ||
|
|
||
| PEP 393 was implemented in Python 3.3 which is released in 2012. Old | ||
| APIs were deprecated since then, and the removal was scheduled in | ||
| Python 4.0. | ||
|
|
||
| Python 4.0 was expected as next version of Python 3.9 when PEP 393 | ||
| was accepted. But the next version of Python 3.9 is Python 3.10, | ||
| not 4.0. This is why this PEP schedule the removal plan again. | ||
|
|
||
|
|
||
| Python 2 reached EOL | ||
| -------------------- | ||
|
|
||
| Since Python 2 didn't have PEP 393 Unicode implementation, legacy | ||
| APIs might help C extensiom modules supporting both of Python 2 and 3. | ||
|
|
||
| But Python 2 reached the EOL in 2020. We can remove legacy APIs kept | ||
| for compatibility with Python 2. | ||
|
|
||
|
|
||
| Plan | ||
| ==== | ||
|
|
||
| Python 3.9 (current) | ||
| -------------------- | ||
|
|
||
| These macros and functions are marked as deprecated, using | ||
| ``Py_DEPRECATED`` macro. | ||
|
|
||
| * ``Py_UNICODE_WSTR_LENGTH()`` | ||
| * ``PyUnicode_GET_SIZE()`` | ||
| * ``PyUnicode_GetSize()`` | ||
| * ``PyUnicode_GET_DATA_SIZE()`` | ||
| * ``PyUnicode_AS_UNICODE()`` | ||
| * ``PyUnicode_AS_DATA()`` | ||
| * ``PyUnicode_AsUnicode()`` | ||
| * ``_PyUnicode_AsUnicode()`` | ||
| * ``PyUnicode_AsUnicodeAndSize()`` | ||
| * ``PyUnicode_FromUnicode()`` | ||
|
|
||
|
|
||
| Python 3.10 | ||
| ----------- | ||
|
|
||
| * Following macros, enum members will be marked as deprecated. | ||
| ``Py_DEPRECATED(3.10)`` macro will be used as possible. But they | ||
| will be deprecated only in comment and document if the macro can | ||
| not be used easily. | ||
|
|
||
| * ``PyUnicode_WCHAR_KIND`` | ||
| * ``PyUnicode_READY()`` | ||
| * ``PyUnicode_IS_READY()`` | ||
| * ``PyUnicode_IS_COMPACT()`` | ||
|
|
||
| * ``PyUnicode_FromUnicode(NULL, size)`` and | ||
| ``PyUnicode_FromStringAndSize(NULL, size)`` will emit | ||
| ``DeprecationWarning`` when ``size > 0``. | ||
|
|
||
| * ``PyArg_ParseTuple()`` and ``PyArg_ParseTupleAndKeywords()`` will emit | ||
| ``DeprecationWarning`` when ``u``, ``u#``, ``Z``, and ``Z#`` formats are used. | ||
|
|
||
|
|
||
| Python 3.12 | ||
| ----------- | ||
|
|
||
| * Following members will be removed from the Unicode strucutres: | ||
|
|
||
| * ``wstr`` | ||
| * ``wstr_length`` | ||
| * ``state.compact`` | ||
| * ``state.ready`` | ||
|
|
||
| * The ``PyUnicodeObject`` struct will be removed. | ||
|
|
||
| * Following macros and functions, and enum members will be removed: | ||
|
|
||
| * ``Py_UNICODE_WSTR_LENGTH()`` | ||
| * ``PyUnicode_GET_SIZE()`` | ||
| * ``PyUnicode_GetSize()`` | ||
| * ``PyUnicode_GET_DATA_SIZE()`` | ||
| * ``PyUnicode_AS_UNICODE()`` | ||
| * ``PyUnicode_AS_DATA()`` | ||
| * ``PyUnicode_AsUnicode()`` | ||
| * ``_PyUnicode_AsUnicode()`` | ||
| * ``PyUnicode_AsUnicodeAndSize()`` | ||
| * ``PyUnicode_FromUnicode()`` | ||
| * ``PyUnicode_WCHAR_KIND`` | ||
| * ``PyUnicode_READY()`` | ||
| * ``PyUnicode_IS_READY()`` | ||
| * ``PyUnicode_IS_COMPACT()`` | ||
|
|
||
| * ``PyUnicode_FromStringAndSize(NULL, size))`` will raise | ||
| ``RuntimeError`` when ``size > 0``. | ||
|
|
||
| * ``PyArg_ParseTuple()`` and ``PyArg_ParseTupleAndKeywords()`` will raise | ||
| ``SystemError`` when ``u``, ``u#``, ``Z``, and ``Z#`` formats are used, | ||
| as other unsupported format character. | ||
|
|
||
|
|
||
| References | ||
| ========== | ||
| A collection of URLs used as references through the PEP. | ||
|
|
||
| .. [1] PEP 393 -- Flexible String Representation | ||
| (https://www.python.org/dev/peps/pep-0393/) | ||
|
|
||
|
|
||
| Copyright | ||
| ========= | ||
|
|
||
| This document has been placed in the public domain. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.