> +1 > > Just a note: checking the header in CPython will only give a hint, > since strings created using higher order kinds can still be 100% > ASCII. >
Oh, really? I think checking header is enough for all ready unicode. For example, this is _PyUnicode_EqualToASCIIString implementation: if (PyUnicode_READY(unicode) == -1) { /* Memory error or bad data */ PyErr_Clear(); return non_ready_unicode_equal_to_ascii_string(unicode, str); } if (!PyUnicode_IS_ASCII(unicode)) return 0; And I think str.isascii() can be implemented as: if (PyUnicode_READY(unicode) == -1) { return NULL; } if (PyUnicode_IS_ASCII(unicode)) { Py_RETURN_TRUE; } else { Py_RETURN_FALSE; } _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/