Get rid of "unready" strings. #156
markshannon
started this conversation in
General
Replies: 2 comments
-
PEP 623 has been accepted and PyUnicode_READY() will be removed (or become no-op macro) in Python 3.12. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Fantastic! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The CPython codebase is riddled* with
PyUnicode_READY
checks. Having to check this on the fast path of comparisons and other operations on strings is highly wasteful.Not only that, but it is hard to be sure that we are sufficiently defensive and that we call
PyUnicode_READY
in all places where we need to.Strings are immutable at the Python level, they should also be immutable at the C level.
The
PyUnicode_READY
seems to exist only to provide a false convenience when writing C code that creates strings.I don't know what the best approach is. I suspect that a C-API change will be needed, but maybe there are some other possibilities.
One idea I have is to not create a
str
, but some sort ofUninitializedStr
instance in the offending C-API.The
UninitializedStr
should then attempt to convert itself to astr
when involved in any operation.Not sure how well that would work when the
UninitializedStr
is passed to an APIs that expect astr
.@methane, as the author of PEP 623, do you have any ideas or suggestions?
* About 260 checks.
Beta Was this translation helpful? Give feedback.
All reactions