Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffc5a14

Browse files
CuriousLearnerwillingc
authored andcommitted
bpo-33014: Clarify str.isidentifier docstring (GH-6088)
* bpo-33014: Clarify str.isidentifier docstring * bpo-33014: Add code example in isidentifier documentation
1 parent 656d52d commit ffc5a14

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,8 +1700,19 @@ expression support in the :mod:`re` module).
17001700
Return true if the string is a valid identifier according to the language
17011701
definition, section :ref:`identifiers`.
17021702

1703-
Use :func:`keyword.iskeyword` to test for reserved identifiers such as
1704-
:keyword:`def` and :keyword:`class`.
1703+
Call :func:`keyword.iskeyword` to test whether string ``s`` is a reserved
1704+
identifier, such as :keyword:`def` and :keyword:`class`.
1705+
1706+
Example:
1707+
::
1708+
1709+
>>> from keyword import iskeyword
1710+
1711+
>>> 'hello'.isidentifier(), iskeyword('hello')
1712+
True, False
1713+
>>> 'def'.isidentifier(), iskeyword('def')
1714+
True, True
1715+
17051716

17061717
.. method:: str.islower()
17071718

Objects/clinic/unicodeobject.c.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/unicodeobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12100,13 +12100,13 @@ str.isidentifier as unicode_isidentifier
1210012100
1210112101
Return True if the string is a valid Python identifier, False otherwise.
1210212102
12103-
Use keyword.iskeyword() to test for reserved identifiers such as "def" and
12104-
"class".
12103+
Call keyword.iskeyword(s) to test whether string s is a reserved identifier,
12104+
such as "def" or "class
1210512105
[clinic start generated code]*/
1210612106

1210712107
static PyObject *
1210812108
unicode_isidentifier_impl(PyObject *self)
12109-
/*[clinic end generated code: output=fe585a9666572905 input=916b0a3c9f57e919]*/
12109+
/*[clinic end generated code: output=fe585a9666572905 input=2fb643aafbcf0e1c]*/
1211012110
{
1211112111
return PyBool_FromLong(PyUnicode_IsIdentifier(self));
1211212112
}

0 commit comments

Comments
 (0)