From 1cb2300d864d21a222094d6bdcd3174fc29a1010 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Mon, 12 Mar 2018 23:48:42 +0530 Subject: [PATCH 1/2] bpo-33014: Clarify str.isidentifier docstring --- 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 ad7f578e086069..00aab4d4c59160 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1687,8 +1687,8 @@ expression support in the :mod:`re` module). Return true if the string is a valid identifier according to the language definition, section :ref:`identifiers`. - Use :func:`keyword.iskeyword` to test for reserved identifiers such as - :keyword:`def` and :keyword:`class`. + Call :func:`keyword.iskeyword` to test whether string ``s`` is a reserved + identifier, such as :keyword:`def` and :keyword:`class`. .. method:: str.islower() diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 8072516a8a36d1..cf5f13c6939e78 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -381,8 +381,8 @@ PyDoc_STRVAR(unicode_isidentifier__doc__, "\n" "Return True if the string is a valid Python identifier, False otherwise.\n" "\n" -"Use keyword.iskeyword() to test for reserved identifiers such as \"def\" and\n" -"\"class\"."); +"Call keyword.iskeyword(s) to test whether string s is a reserved identifier,\n" +"such as \"def\" or \"class"); #define UNICODE_ISIDENTIFIER_METHODDEF \ {"isidentifier", (PyCFunction)unicode_isidentifier, METH_NOARGS, unicode_isidentifier__doc__}, @@ -951,4 +951,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return unicode_sizeof_impl(self); } -/*[clinic end generated code: output=561c88c912b8fe3b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c9476bf19f13c286 input=a9049054013a1b77]*/ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 1ae2f5e018fe8e..1a465856c9e301 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -12069,13 +12069,13 @@ str.isidentifier as unicode_isidentifier Return True if the string is a valid Python identifier, False otherwise. -Use keyword.iskeyword() to test for reserved identifiers such as "def" and -"class". +Call keyword.iskeyword(s) to test whether string s is a reserved identifier, +such as "def" or "class [clinic start generated code]*/ static PyObject * unicode_isidentifier_impl(PyObject *self) -/*[clinic end generated code: output=fe585a9666572905 input=916b0a3c9f57e919]*/ +/*[clinic end generated code: output=fe585a9666572905 input=2fb643aafbcf0e1c]*/ { return PyBool_FromLong(PyUnicode_IsIdentifier(self)); } From e6ae68c36ab1e456f4383a6de3d33cee856fbb11 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Sat, 21 Jul 2018 14:25:19 +0530 Subject: [PATCH 2/2] bpo-33014: Add code example in isidentifier documentation --- Doc/library/stdtypes.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 00e23b67729b8d..815680549313a2 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1690,6 +1690,17 @@ expression support in the :mod:`re` module). Call :func:`keyword.iskeyword` to test whether string ``s`` is a reserved identifier, such as :keyword:`def` and :keyword:`class`. + Example: + :: + + >>> from keyword import iskeyword + + >>> 'hello'.isidentifier(), iskeyword('hello') + True, False + >>> 'def'.isidentifier(), iskeyword('def') + True, True + + .. method:: str.islower() Return true if all cased characters [4]_ in the string are lowercase and