]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-33014: Clarify str.isidentifier docstring (GH-6088)
authorSanyam Khurana <8039608+CuriousLearner@users.noreply.github.com>
Mon, 8 Oct 2018 06:53:32 +0000 (12:23 +0530)
committerCarol Willing <carolcode@willingconsulting.com>
Mon, 8 Oct 2018 06:53:32 +0000 (12:23 +0530)
* bpo-33014: Clarify str.isidentifier docstring

* bpo-33014: Add code example in isidentifier documentation

Doc/library/stdtypes.rst
Objects/clinic/unicodeobject.c.h
Objects/unicodeobject.c

index 5a133e32fced7e70567dcf59ae47a6b2d782cbcf..d0d5c6157290f5e5841b0801799a6e071364ae37 100644 (file)
@@ -1700,8 +1700,19 @@ 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`.
+
+   Example:
+   ::
+
+      >>> from keyword import iskeyword
+
+      >>> 'hello'.isidentifier(), iskeyword('hello')
+      True, False
+      >>> 'def'.isidentifier(), iskeyword('def')
+      True, True
+
 
 .. method:: str.islower()
 
index 8072516a8a36d142f1408e065cc626006460e4e2..cf5f13c6939e7840958aa10c08a73f648f9615b8 100644 (file)
@@ -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]*/
index a797f838eb413977caf9cc912c31062e010fefd2..16dd3d19e805357077ebfcfbba66cef064707a5c 100644 (file)
@@ -12100,13 +12100,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));
 }