https://github.com/python/cpython/commit/3a7f17c7e2f72a836a019c316818c446a0c71d75
commit: 3a7f17c7e2f72a836a019c316818c446a0c71d75
branch: main
author: Sergey Miryanov <sergey.mirya...@gmail.com>
committer: vstinner <vstin...@python.org>
date: 2025-03-03T19:18:09Z
summary:

gh-130790: Remove references about unicode's readiness from comments (#130801)

files:
M Include/cpython/unicodeobject.h
M Include/internal/pycore_traceback.h
M Modules/_io/textio.c
M Modules/unicodedata.c
M Objects/typeobject.c
M Objects/unicodeobject.c
M Parser/lexer/lexer.c
M Parser/pegen.c
M Python/codecs.c
M Python/formatter_unicode.c
M Python/tracemalloc.c

diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h
index 463cbf24ce1692..e8b04d158b0805 100644
--- a/Include/cpython/unicodeobject.h
+++ b/Include/cpython/unicodeobject.h
@@ -212,22 +212,21 @@ static inline unsigned int PyUnicode_IS_READY(PyObject* 
Py_UNUSED(op)) {
 #define PyUnicode_IS_READY(op) PyUnicode_IS_READY(_PyObject_CAST(op))
 
 /* Return true if the string contains only ASCII characters, or 0 if not. The
-   string may be compact (PyUnicode_IS_COMPACT_ASCII) or not, but must be
-   ready. */
+   string may be compact (PyUnicode_IS_COMPACT_ASCII) or not. */
 static inline unsigned int PyUnicode_IS_ASCII(PyObject *op) {
     return _PyASCIIObject_CAST(op)->state.ascii;
 }
 #define PyUnicode_IS_ASCII(op) PyUnicode_IS_ASCII(_PyObject_CAST(op))
 
 /* Return true if the string is compact or 0 if not.
-   No type checks or Ready calls are performed. */
+   No type checks are performed. */
 static inline unsigned int PyUnicode_IS_COMPACT(PyObject *op) {
     return _PyASCIIObject_CAST(op)->state.compact;
 }
 #define PyUnicode_IS_COMPACT(op) PyUnicode_IS_COMPACT(_PyObject_CAST(op))
 
 /* Return true if the string is a compact ASCII string (use PyASCIIObject
-   structure), or 0 if not.  No type checks or Ready calls are performed. */
+   structure), or 0 if not.  No type checks are performed. */
 static inline int PyUnicode_IS_COMPACT_ASCII(PyObject *op) {
     return (_PyASCIIObject_CAST(op)->state.ascii && PyUnicode_IS_COMPACT(op));
 }
@@ -319,7 +318,7 @@ static inline void PyUnicode_WRITE(int kind, void *data,
                     (index), _Py_STATIC_CAST(Py_UCS4, value))
 
 /* Read a code point from the string's canonical representation.  No checks
-   or ready calls are performed. */
+   are performed. */
 static inline Py_UCS4 PyUnicode_READ(int kind,
                                      const void *data, Py_ssize_t index)
 {
diff --git a/Include/internal/pycore_traceback.h 
b/Include/internal/pycore_traceback.h
index 10922bff98bd4b..741108a957a35c 100644
--- a/Include/internal/pycore_traceback.h
+++ b/Include/internal/pycore_traceback.h
@@ -66,8 +66,7 @@ extern const char* _Py_DumpTracebackThreads(
 /* Write a Unicode object into the file descriptor fd. Encode the string to
    ASCII using the backslashreplace error handler.
 
-   Do nothing if text is not a Unicode object. The function accepts Unicode
-   string which is not ready (PyUnicode_WCHAR_KIND).
+   Do nothing if text is not a Unicode object.
 
    This function is signal safe. */
 extern void _Py_DumpASCII(int fd, PyObject *text);
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 935aaab20a031f..071a06ffbf7334 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -358,7 +358,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *myself,
         out = PyUnicode_DATA(modified);
         PyUnicode_WRITE(kind, out, 0, '\r');
         memcpy(out + kind, PyUnicode_DATA(output), kind * output_len);
-        Py_SETREF(output, modified); /* output remains ready */
+        Py_SETREF(output, modified);
         self->pendingcr = 0;
         output_len++;
     }
@@ -1818,7 +1818,6 @@ textiowrapper_get_decoded_chars(textio *self, Py_ssize_t 
n)
     if (self->decoded_chars == NULL)
         return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
 
-    /* decoded_chars is guaranteed to be "ready". */
     avail = (PyUnicode_GET_LENGTH(self->decoded_chars)
              - self->decoded_chars_used);
 
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index f1ff7bd3eba232..ef8cf3d0d27459 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -591,7 +591,7 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
     PyMem_Free(output);
     if (!result)
         return NULL;
-    /* result is guaranteed to be ready, as it is compact. */
+
     kind = PyUnicode_KIND(result);
     data = PyUnicode_DATA(result);
 
@@ -655,7 +655,7 @@ nfc_nfkc(PyObject *self, PyObject *input, int k)
     result = nfd_nfkd(self, input, k);
     if (!result)
         return NULL;
-    /* result will be "ready". */
+
     kind = PyUnicode_KIND(result);
     data = PyUnicode_DATA(result);
     len = PyUnicode_GET_LENGTH(result);
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index f667e56afbbf8b..bc840ed51ffe4c 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -49,7 +49,6 @@ class object "PyObject *" "&PyBaseObject_Type"
                 ((Py_ssize_t)(name)) >> 3)
 #define MCACHE_CACHEABLE_NAME(name)                             \
         PyUnicode_CheckExact(name) &&                           \
-        PyUnicode_IS_READY(name) &&                             \
         (PyUnicode_GET_LENGTH(name) <= MCACHE_MAX_ATTR_SIZE)
 
 #define NEXT_GLOBAL_VERSION_TAG _PyRuntime.types.next_version_tag
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 0686276c502aaf..20052e2d17062d 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -15952,7 +15952,6 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
     Py_ssize_t pos = 0;
     PyObject *s, *ignored_value;
     while (PyDict_Next(interned, &pos, &s, &ignored_value)) {
-        assert(PyUnicode_IS_READY(s));
         int shared = 0;
         switch (PyUnicode_CHECK_INTERNED(s)) {
         case SSTATE_INTERNED_IMMORTAL:
diff --git a/Parser/lexer/lexer.c b/Parser/lexer/lexer.c
index 207fb6b363766c..45604b197f43f2 100644
--- a/Parser/lexer/lexer.c
+++ b/Parser/lexer/lexer.c
@@ -308,9 +308,7 @@ verify_end_of_number(struct tok_state *tok, int c, const 
char *kind) {
     return 1;
 }
 
-/* Verify that the identifier follows PEP 3131.
-   All identifier strings are guaranteed to be "ready" unicode objects.
- */
+/* Verify that the identifier follows PEP 3131. */
 static int
 verify_identifier(struct tok_state *tok)
 {
diff --git a/Parser/pegen.c b/Parser/pegen.c
index 83b0022e47d619..be1768d0f2cff7 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -509,8 +509,6 @@ _PyPegen_new_identifier(Parser *p, const char *n)
     if (!id) {
         goto error;
     }
-    /* PyUnicode_DecodeUTF8 should always return a ready string. */
-    assert(PyUnicode_IS_READY(id));
     /* Check whether there are non-ASCII characters in the
        identifier; if so, normalize to NFKC. */
     if (!PyUnicode_IS_ASCII(id))
diff --git a/Python/codecs.c b/Python/codecs.c
index 8cdebfa1b611ea..2453929c8c789a 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -1256,7 +1256,6 @@ _PyCodec_SurrogatePassUnicodeEncodeError(PyObject *exc)
 
     unsigned char *outp = (unsigned char *)PyBytes_AsString(res);
     for (Py_ssize_t i = start; i < end; i++) {
-        /* object is guaranteed to be "ready" */
         Py_UCS4 ch = PyUnicode_READ_CHAR(obj, i);
         if (!Py_UNICODE_IS_SURROGATE(ch)) {
             /* Not a surrogate, fail with original exception */
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c
index 4f8662b0a4c8fb..6e3dcb3dd66373 100644
--- a/Python/formatter_unicode.c
+++ b/Python/formatter_unicode.c
@@ -867,7 +867,6 @@ format_string_internal(PyObject *value, const 
InternalFormatSpec *format,
     int result = -1;
     Py_UCS4 maxchar;
 
-    assert(PyUnicode_IS_READY(value));
     len = PyUnicode_GET_LENGTH(value);
 
     /* sign is not allowed on strings */
diff --git a/Python/tracemalloc.c b/Python/tracemalloc.c
index d69b0ebd585a7f..1ee040dde2262d 100644
--- a/Python/tracemalloc.c
+++ b/Python/tracemalloc.c
@@ -249,14 +249,6 @@ tracemalloc_get_frame(_PyInterpreterFrame *pyframe, 
frame_t *frame)
 #endif
         return;
     }
-    if (!PyUnicode_IS_READY(filename)) {
-        /* Don't make a Unicode string ready to avoid reentrant calls
-           to tracemalloc_alloc() or tracemalloc_realloc() */
-#ifdef TRACE_DEBUG
-        tracemalloc_error("filename is not a ready unicode string");
-#endif
-        return;
-    }
 
     /* intern the filename */
     _Py_hashtable_entry_t *entry;

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to