From 1d4c0f4adc591563a786bed680a9f7b2d0d6fe9c Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 26 Jan 2018 19:53:56 +0900 Subject: [PATCH 01/12] Implement str.isascii() --- Objects/clinic/unicodeobject.c.h | 22 +++++++++++++++++++++- Objects/unicodeobject.c | 23 +++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 643ef0491b349d..3a52f1d5b4f4aa 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -165,6 +165,26 @@ unicode_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb return return_value; } +PyDoc_STRVAR(unicode_isascii__doc__, +"isascii($self, /)\n" +"--\n" +"\n" +"Return True if the string is an ascii string, False otherwise.\n" +"\n" +"A string is ascii if all(ord(c) < 128 in string)."); + +#define UNICODE_ISASCII_METHODDEF \ + {"isascii", (PyCFunction)unicode_isascii, METH_NOARGS, unicode_isascii__doc__}, + +static PyObject * +unicode_isascii_impl(PyObject *self); + +static PyObject * +unicode_isascii(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + return unicode_isascii_impl(self); +} + PyDoc_STRVAR(unicode_islower__doc__, "islower($self, /)\n" "--\n" @@ -930,4 +950,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return unicode_sizeof_impl(self); } -/*[clinic end generated code: output=1ad4e81b68194264 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=150b36c8792a4d80 input=a9049054013a1b77]*/ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 07330119dc3038..daf8fdb8fc9d73 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -11611,6 +11611,28 @@ unicode_index(PyObject *self, PyObject *args) return PyLong_FromSsize_t(result); } +/*[clinic input] +str.isascii as unicode_isascii + +Return True if the string is an ascii string, False otherwise. + +A string is ascii if all(ord(c) < 128 in string). +[clinic start generated code]*/ + +static PyObject * +unicode_isascii_impl(PyObject *self) +/*[clinic end generated code: output=c5910d64b5a8003f input=73b30d38f16965cd]*/ +{ + if (PyUnicode_READY(self) == -1) + return NULL; + if (PyUnicode_IS_ASCII(self)) { + Py_RETURN_TRUE; + } + else { + Py_RETURN_FALSE; + } +} + /*[clinic input] str.islower as unicode_islower @@ -13801,6 +13823,7 @@ static PyMethodDef unicode_methods[] = { UNICODE_UPPER_METHODDEF {"startswith", (PyCFunction) unicode_startswith, METH_VARARGS, startswith__doc__}, {"endswith", (PyCFunction) unicode_endswith, METH_VARARGS, endswith__doc__}, + UNICODE_ISASCII_METHODDEF UNICODE_ISLOWER_METHODDEF UNICODE_ISUPPER_METHODDEF UNICODE_ISTITLE_METHODDEF From 4b01174d20f3b45aa3ad817ee34575cf0bbc364a Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 26 Jan 2018 20:04:05 +0900 Subject: [PATCH 02/12] Add tests and doc --- Doc/library/stdtypes.rst | 8 ++++++++ Lib/test/test_unicode.py | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 120b0d3399c8b5..baf72cd89411c1 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1653,6 +1653,14 @@ expression support in the :mod:`re` module). from the "Alphabetic" property defined in the Unicode Standard. +.. method:: str.isascii() + + Return true if all characters in the string are ASCII, false otherwise. + ASCII characters are characters which :func:`ord` returns less than 128. + + .. versionadded:: 3.7 + + .. method:: str.isdecimal() Return true if all characters in the string are decimal diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 2b77863e52e490..63d2129de23c76 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -638,6 +638,16 @@ def test_isalpha(self): self.assertFalse('\U0001F40D'.isalpha()) self.assertFalse('\U0001F46F'.isalpha()) + def test_isascii(self): + self.assertTrue("".isascii()) + self.assertTrue("\0".isascii()) + self.assertTrue("\x7f".isascii()) + self.assertFalse("\x80".isascii()) + self.assertTrue(" \x7f".isascii()) + self.assertFalse(" \x80".isascii()) + self.assertTrue("\x7f ".isascii()) + self.assertFalse("\x80 ".isascii()) + def test_isdecimal(self): self.checkequalnofix(False, '', 'isdecimal') self.checkequalnofix(False, 'a', 'isdecimal') From 8b6452f6a92e035be9fb066c8458168d63f1690d Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 26 Jan 2018 20:11:12 +0900 Subject: [PATCH 03/12] Add NEWS entry --- .../Core and Builtins/2018-01-26-20-11-09.bpo-32677.xTGfCq.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2018-01-26-20-11-09.bpo-32677.xTGfCq.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-01-26-20-11-09.bpo-32677.xTGfCq.rst b/Misc/NEWS.d/next/Core and Builtins/2018-01-26-20-11-09.bpo-32677.xTGfCq.rst new file mode 100644 index 00000000000000..79664facec1dc5 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-01-26-20-11-09.bpo-32677.xTGfCq.rst @@ -0,0 +1,2 @@ +Add ``str.isascii()`` method to check the string contains only ASCII +characters or not. From 120579af5db284d2a1de5ad01e7ece8dbf581269 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 26 Jan 2018 20:18:20 +0900 Subject: [PATCH 04/12] fix --- Objects/unicodeobject.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index daf8fdb8fc9d73..daa6df5d47b226 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -11623,14 +11623,10 @@ static PyObject * unicode_isascii_impl(PyObject *self) /*[clinic end generated code: output=c5910d64b5a8003f input=73b30d38f16965cd]*/ { - if (PyUnicode_READY(self) == -1) + if (PyUnicode_READY(self) == -1) { return NULL; - if (PyUnicode_IS_ASCII(self)) { - Py_RETURN_TRUE; - } - else { - Py_RETURN_FALSE; } + return PyBool_FromLong(PyUnicode_IS_ASCII(self)); } /*[clinic input] From 22a840023ffed0708ebb63e53e1919098defc20b Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 26 Jan 2018 21:02:48 +0900 Subject: [PATCH 05/12] s/ascii/ASCII/ --- Objects/clinic/unicodeobject.c.h | 6 +++--- Objects/unicodeobject.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 3a52f1d5b4f4aa..2243c3387332a2 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -169,9 +169,9 @@ PyDoc_STRVAR(unicode_isascii__doc__, "isascii($self, /)\n" "--\n" "\n" -"Return True if the string is an ascii string, False otherwise.\n" +"Return True if the string is an ASCII string, False otherwise.\n" "\n" -"A string is ascii if all(ord(c) < 128 in string)."); +"A string is ASCII if all(ord(c) < 128 in string)."); #define UNICODE_ISASCII_METHODDEF \ {"isascii", (PyCFunction)unicode_isascii, METH_NOARGS, unicode_isascii__doc__}, @@ -950,4 +950,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return unicode_sizeof_impl(self); } -/*[clinic end generated code: output=150b36c8792a4d80 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=dd4908665b041529 input=a9049054013a1b77]*/ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index daa6df5d47b226..5283a2aed346a1 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -11614,14 +11614,14 @@ unicode_index(PyObject *self, PyObject *args) /*[clinic input] str.isascii as unicode_isascii -Return True if the string is an ascii string, False otherwise. +Return True if the string is an ASCII string, False otherwise. -A string is ascii if all(ord(c) < 128 in string). +A string is ASCII if all(ord(c) < 128 in string). [clinic start generated code]*/ static PyObject * unicode_isascii_impl(PyObject *self) -/*[clinic end generated code: output=c5910d64b5a8003f input=73b30d38f16965cd]*/ +/*[clinic end generated code: output=c5910d64b5a8003f input=6ea6763eac6c0352]*/ { if (PyUnicode_READY(self) == -1) { return NULL; From 56b7727d91fc7d044c842b84a93f8a35033f1b61 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 26 Jan 2018 21:05:11 +0900 Subject: [PATCH 06/12] Fix UserString --- Lib/collections/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 7088b88e04a788..21d91fd61d607c 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -1214,6 +1214,7 @@ def index(self, sub, start=0, end=_sys.maxsize): return self.data.index(sub, start, end) def isalpha(self): return self.data.isalpha() def isalnum(self): return self.data.isalnum() + def isascii(self): return self.data.isascii() def isdecimal(self): return self.data.isdecimal() def isdigit(self): return self.data.isdigit() def isidentifier(self): return self.data.isidentifier() From 3fb324094f046d69fe3616f53484b68a77aca981 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 26 Jan 2018 22:13:50 +0900 Subject: [PATCH 07/12] Update doc with Victor's suggestion --- Doc/library/stdtypes.rst | 3 ++- Objects/clinic/unicodeobject.c.h | 5 +++-- Objects/unicodeobject.c | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index baf72cd89411c1..359a028b34624d 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1656,7 +1656,8 @@ expression support in the :mod:`re` module). .. method:: str.isascii() Return true if all characters in the string are ASCII, false otherwise. - ASCII characters are characters which :func:`ord` returns less than 128. + ASCII characters have code points in the range U+0000-U+007F. + Empty string is ASCII string too. .. versionadded:: 3.7 diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 2243c3387332a2..4df19b53a1e86f 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -171,7 +171,8 @@ PyDoc_STRVAR(unicode_isascii__doc__, "\n" "Return True if the string is an ASCII string, False otherwise.\n" "\n" -"A string is ASCII if all(ord(c) < 128 in string)."); +"ASCII characters have code points in the range U+0000-U+007F.\n" +"Empty string is ASCII string too."); #define UNICODE_ISASCII_METHODDEF \ {"isascii", (PyCFunction)unicode_isascii, METH_NOARGS, unicode_isascii__doc__}, @@ -950,4 +951,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return unicode_sizeof_impl(self); } -/*[clinic end generated code: output=dd4908665b041529 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3391d1cd3a1633cc input=a9049054013a1b77]*/ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 5283a2aed346a1..2a1c9fbb706949 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -11616,12 +11616,13 @@ str.isascii as unicode_isascii Return True if the string is an ASCII string, False otherwise. -A string is ASCII if all(ord(c) < 128 in string). +ASCII characters have code points in the range U+0000-U+007F. +Empty string is ASCII string too. [clinic start generated code]*/ static PyObject * unicode_isascii_impl(PyObject *self) -/*[clinic end generated code: output=c5910d64b5a8003f input=6ea6763eac6c0352]*/ +/*[clinic end generated code: output=c5910d64b5a8003f input=b4856faff03f9dbd]*/ { if (PyUnicode_READY(self) == -1) { return NULL; From 949b3ad4b37396de942c8a136ec86c52f7a57eb4 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 27 Jan 2018 01:44:39 +0900 Subject: [PATCH 08/12] Update doc --- Doc/library/stdtypes.rst | 4 ++-- Objects/clinic/unicodeobject.c.h | 6 +++--- Objects/unicodeobject.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 359a028b34624d..67a391f19a1b50 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1655,9 +1655,9 @@ expression support in the :mod:`re` module). .. method:: str.isascii() - Return true if all characters in the string are ASCII, false otherwise. + Return true if the string is empty or all characters in the string are ASCII, + false otherwise. ASCII characters have code points in the range U+0000-U+007F. - Empty string is ASCII string too. .. versionadded:: 3.7 diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 4df19b53a1e86f..8072516a8a36d1 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -169,10 +169,10 @@ PyDoc_STRVAR(unicode_isascii__doc__, "isascii($self, /)\n" "--\n" "\n" -"Return True if the string is an ASCII string, False otherwise.\n" +"Return True if all characters in the string are ASCII, False otherwise.\n" "\n" "ASCII characters have code points in the range U+0000-U+007F.\n" -"Empty string is ASCII string too."); +"Empty string is ASCII too."); #define UNICODE_ISASCII_METHODDEF \ {"isascii", (PyCFunction)unicode_isascii, METH_NOARGS, unicode_isascii__doc__}, @@ -951,4 +951,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return unicode_sizeof_impl(self); } -/*[clinic end generated code: output=3391d1cd3a1633cc input=a9049054013a1b77]*/ +/*[clinic end generated code: output=561c88c912b8fe3b input=a9049054013a1b77]*/ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 2a1c9fbb706949..4b90cc364b8c02 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -11614,15 +11614,15 @@ unicode_index(PyObject *self, PyObject *args) /*[clinic input] str.isascii as unicode_isascii -Return True if the string is an ASCII string, False otherwise. +Return True if all characters in the string are ASCII, False otherwise. ASCII characters have code points in the range U+0000-U+007F. -Empty string is ASCII string too. +Empty string is ASCII too. [clinic start generated code]*/ static PyObject * unicode_isascii_impl(PyObject *self) -/*[clinic end generated code: output=c5910d64b5a8003f input=b4856faff03f9dbd]*/ +/*[clinic end generated code: output=c5910d64b5a8003f input=5a43cbc6399621d5]*/ { if (PyUnicode_READY(self) == -1) { return NULL; From 5289baedf0db69f4eb4f08531159c27bc0cc1a09 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 27 Jan 2018 01:55:54 +0900 Subject: [PATCH 09/12] Add bytes.isascii() and bytearray.isascii() --- Doc/library/stdtypes.rst | 10 ++++++++++ Include/bytes_methods.h | 2 ++ Objects/bytearrayobject.c | 2 ++ Objects/bytes_methods.c | 20 ++++++++++++++++++++ Objects/bytesobject.c | 2 ++ Objects/stringlib/ctype.h | 6 ++++++ 6 files changed, 42 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 67a391f19a1b50..ad7f578e086069 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2950,6 +2950,16 @@ place, and instead produce new objects. False +.. method:: bytes.isascii() + bytearray.isascii() + + Return true if the sequence is empty or all bytes in the sequence are ASCII, + false otherwise. + ASCII bytes are in the range 0-0x7F. + + .. versionadded:: 3.7 + + .. method:: bytes.isdigit() bytearray.isdigit() diff --git a/Include/bytes_methods.h b/Include/bytes_methods.h index 7fa7540c38b731..8434a50a4bba71 100644 --- a/Include/bytes_methods.h +++ b/Include/bytes_methods.h @@ -9,6 +9,7 @@ extern PyObject* _Py_bytes_isspace(const char *cptr, Py_ssize_t len); extern PyObject* _Py_bytes_isalpha(const char *cptr, Py_ssize_t len); extern PyObject* _Py_bytes_isalnum(const char *cptr, Py_ssize_t len); +extern PyObject* _Py_bytes_isascii(const char *cptr, Py_ssize_t len); extern PyObject* _Py_bytes_isdigit(const char *cptr, Py_ssize_t len); extern PyObject* _Py_bytes_islower(const char *cptr, Py_ssize_t len); extern PyObject* _Py_bytes_isupper(const char *cptr, Py_ssize_t len); @@ -37,6 +38,7 @@ extern PyObject* _Py_bytes_maketrans(Py_buffer *frm, Py_buffer *to); extern const char _Py_isspace__doc__[]; extern const char _Py_isalpha__doc__[]; extern const char _Py_isalnum__doc__[]; +extern const char _Py_isascii__doc__[]; extern const char _Py_isdigit__doc__[]; extern const char _Py_islower__doc__[]; extern const char _Py_isupper__doc__[]; diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index dc1515a059cb94..692b7be7392455 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2159,6 +2159,8 @@ bytearray_methods[] = { _Py_isalnum__doc__}, {"isalpha", (PyCFunction)stringlib_isalpha, METH_NOARGS, _Py_isalpha__doc__}, + {"isascii", (PyCFunction)stringlib_isascii, METH_NOARGS, + _Py_isascii__doc__}, {"isdigit", (PyCFunction)stringlib_isdigit, METH_NOARGS, _Py_isdigit__doc__}, {"islower", (PyCFunction)stringlib_islower, METH_NOARGS, diff --git a/Objects/bytes_methods.c b/Objects/bytes_methods.c index bd79773a54eabf..149650f018fcb6 100644 --- a/Objects/bytes_methods.c +++ b/Objects/bytes_methods.c @@ -92,6 +92,26 @@ _Py_bytes_isalnum(const char *cptr, Py_ssize_t len) } +PyDoc_STRVAR_shared(_Py_isascii__doc__, +"B.isascii() -> bool\n\ +\n\ +Return True if B is empty or all characters in B are ASCII,\n\ +False otherwise."); + +PyObject* +_Py_bytes_isascii(const char *cptr, Py_ssize_t len) +{ + const unsigned char *p = (unsigned char *) cptr; + const unsigned char *e = p + len; + for (; p < e; p++) { + if (*p >= 128) { + Py_RETURN_FALSE; + } + } + Py_RETURN_TRUE; +} + + PyDoc_STRVAR_shared(_Py_isdigit__doc__, "B.isdigit() -> bool\n\ \n\ diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index a921d9cb8c5e98..c358756bfea8e6 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2459,6 +2459,8 @@ bytes_methods[] = { _Py_isalnum__doc__}, {"isalpha", (PyCFunction)stringlib_isalpha, METH_NOARGS, _Py_isalpha__doc__}, + {"isascii", (PyCFunction)stringlib_isascii, METH_NOARGS, + _Py_isascii__doc__}, {"isdigit", (PyCFunction)stringlib_isdigit, METH_NOARGS, _Py_isdigit__doc__}, {"islower", (PyCFunction)stringlib_islower, METH_NOARGS, diff --git a/Objects/stringlib/ctype.h b/Objects/stringlib/ctype.h index f0546256ed911c..fd7b1bd49e54f7 100644 --- a/Objects/stringlib/ctype.h +++ b/Objects/stringlib/ctype.h @@ -22,6 +22,12 @@ stringlib_isalnum(PyObject *self) return _Py_bytes_isalnum(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } +static PyObject* +stringlib_isascii(PyObject *self) +{ + return _Py_bytes_isascii(STRINGLIB_STR(self), STRINGLIB_LEN(self)); +} + static PyObject* stringlib_isdigit(PyObject *self) { From 40e08a0b2b42ccef9d8b8331543c25718275f1dd Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 27 Jan 2018 02:03:02 +0900 Subject: [PATCH 10/12] Add test for bytes.isascii() --- Lib/test/string_tests.py | 8 ++++++++ Lib/test/test_unicode.py | 11 +++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index cd3ee48a92bb7d..4be1d2118978a9 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -909,6 +909,14 @@ def test_isalnum(self): self.checkequal(False, 'abc\n', 'isalnum') self.checkraises(TypeError, 'abc', 'isalnum', 42) + def test_isascii(self): + self.checkequal(True, '', 'isascii') + self.checkequal(True, '\x00', 'isascii') + self.checkequal(True, '\x7f', 'isascii') + self.checkequal(True, '\x00\x7f', 'isascii') + self.checkequal(False, '\x80', 'isascii') + self.checkequal(False, '\xe9', 'isascii') + def test_isdigit(self): self.checkequal(False, '', 'isdigit') self.checkequal(False, 'a', 'isdigit') diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 63d2129de23c76..3cc018c0cc2caa 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -639,14 +639,9 @@ def test_isalpha(self): self.assertFalse('\U0001F46F'.isalpha()) def test_isascii(self): - self.assertTrue("".isascii()) - self.assertTrue("\0".isascii()) - self.assertTrue("\x7f".isascii()) - self.assertFalse("\x80".isascii()) - self.assertTrue(" \x7f".isascii()) - self.assertFalse(" \x80".isascii()) - self.assertTrue("\x7f ".isascii()) - self.assertFalse("\x80 ".isascii()) + super().test_isascii() + self.assertFalse("\u20ac".isascii()) + self.assertFalse("\U0010ffff".isascii()) def test_isdecimal(self): self.checkequalnofix(False, '', 'isdecimal') From 4138202ed42d615942f2edf69ffd7215d4546ef4 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 27 Jan 2018 09:49:25 +0900 Subject: [PATCH 11/12] Fix test_doctest --- Lib/test/test_doctest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 2258c6b1baed26..5ad94aba6492ab 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -659,7 +659,7 @@ def non_Python_modules(): r""" >>> import builtins >>> tests = doctest.DocTestFinder().find(builtins) - >>> 790 < len(tests) < 810 # approximate number of objects with docstrings + >>> 800 < len(tests) < 820 # approximate number of objects with docstrings True >>> real_tests = [t for t in tests if len(t.examples) > 0] >>> len(real_tests) # objects that actually have doctests From 91a6b18bb243ac5dd9e88d2cc50134f94b723586 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 27 Jan 2018 10:27:23 +0900 Subject: [PATCH 12/12] Update NEWS entry --- .../2018-01-26-20-11-09.bpo-32677.xTGfCq.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-01-26-20-11-09.bpo-32677.xTGfCq.rst b/Misc/NEWS.d/next/Core and Builtins/2018-01-26-20-11-09.bpo-32677.xTGfCq.rst index 79664facec1dc5..947c74f130b243 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2018-01-26-20-11-09.bpo-32677.xTGfCq.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2018-01-26-20-11-09.bpo-32677.xTGfCq.rst @@ -1,2 +1,2 @@ -Add ``str.isascii()`` method to check the string contains only ASCII -characters or not. +Add ``.isascii()`` method to ``str``, ``bytes`` and ``bytearray``. +It can be used to test that string contains only ASCII characters.