bpo-31393: Fix the use of PyUnicode_READY(). (#3451)

diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index eee9bfe..adef625 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -27,7 +27,7 @@
     };
     const unsigned char *s, *e;
 
-    if (PyUnicode_READY(o) == -1 || !PyUnicode_IS_ASCII(o))
+    if (!PyUnicode_IS_ASCII(o))
         return 0;
 
     s = PyUnicode_1BYTE_DATA(o);
@@ -63,6 +63,10 @@
     for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) {
         PyObject *v = PyTuple_GET_ITEM(tuple, i);
         if (PyUnicode_CheckExact(v)) {
+            if (PyUnicode_READY(v) == -1) {
+                PyErr_Clear();
+                continue;
+            }
             if (all_name_chars(v)) {
                 PyObject *w = v;
                 PyUnicode_InternInPlace(&v);