[Python-ideas] Adding str.isascii() ?

INADA Naoki songofacandy at gmail.com
Fri Jan 26 08:33:36 EST 2018


>
> Can you create a simple test-case that proves this?

Sure.

$ git diff
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 2ad4322eca..475d5219e1 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -5307,6 +5307,12 @@ PyInit__testcapi(void)
     Py_INCREF(&PyInstanceMethod_Type);
     PyModule_AddObject(m, "instancemethod", (PyObject
*)&PyInstanceMethod_Type);

+    PyObject *wrong_unicode = PyUnicode_New(1, 65535);
+    PyUnicode_WRITE(PyUnicode_2BYTE_KIND,
+            PyUnicode_DATA(wrong_unicode),
+            0, 'a');
+    PyModule_AddObject(m, "wrong_unicode", wrong_unicode);
+
     PyModule_AddIntConstant(m, "the_number_three", 3);
 #ifdef WITH_PYMALLOC
     PyModule_AddObject(m, "WITH_PYMALLOC", Py_True);

$ ./python
Python 3.7.0a4+ (heads/master-dirty:e76daebc0c, Jan 26 2018, 22:31:18)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import _testcapi
>>> _testcapi.wrong_unicode
'a'
>>> len(_testcapi.wrong_unicode)
1
>>> ord(_testcapi.wrong_unicode)
97
>>> _testcapi.wrong_unicode == 'a'
False
>>>


More information about the Python-ideas mailing list