Visitar URL original
gh-129117: Expose `_PyUnicode_IsXidContinue/Start` in `unicodedata` by StanFromIreland 路 Pull Request #140269 路 python/cpython 路 GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Part of review
  • Loading branch information
StanFromIreland committed Oct 29, 2025
commit cf197af67d65baa44049cb8f8feeeb99c611cf90
10 changes: 6 additions & 4 deletions Doc/library/unicodedata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ following functions:

.. function:: isidstart(chr, /)

Return ``True`` if the character has the ``XID_Start`` property, ``False``
otherwise. For example::
Return ``True`` if *chr* is a valid identifier start per the
`Unicode Standard Annex #31 <https://www.unicode.org/reports/tr31/>`_,
that is, it has the ``XID_Start`` property, ``False`` otherwise. For example::
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated

>>> unicodedata.isidstart('S')
True
Expand All @@ -159,8 +160,9 @@ following functions:

.. function:: isidcontinue(chr, /)

Return ``True`` if the character has the ``XID_Continue`` property, ``False``
otherwise. For example::
Return ``True`` if *chr* is a valid identifier charcter per the
Comment thread
vstinner marked this conversation as resolved.
Outdated
`Unicode Standard Annex #31 <https://www.unicode.org/reports/tr31/>`_,
that is, it has the ``XID_Continue`` property, ``False`` otherwise. For example::

>>> unicodedata.isidcontinue('S')
True
Expand Down
12 changes: 4 additions & 8 deletions Modules/unicodedata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,17 +1541,15 @@ static PyObject *
unicodedata_UCD_isidstart_impl(PyObject *self, int chr)
/*[clinic end generated code: output=29fbeaf6491d9f85 input=b71b6b1b2db3c16d]*/
{
Py_UCS4 c = (Py_UCS4)chr;

if (UCD_Check(self)) {
const change_record *old = get_old_record(self, c);
const change_record *old = get_old_record(self, chr);
if (old->category_changed == 0) {
/* unassigned */
Py_RETURN_FALSE;
}
}

return PyBool_FromLong(_PyUnicode_IsXidStart(c));
return PyBool_FromLong(_PyUnicode_IsXidStart(chr));
}

/*[clinic input]
Expand All @@ -1569,17 +1567,15 @@ static PyObject *
unicodedata_UCD_isidcontinue_impl(PyObject *self, int chr)
/*[clinic end generated code: output=5ae694da0ee16534 input=01b4ccd399484e6b]*/
{
Py_UCS4 c = (Py_UCS4)chr;

if (UCD_Check(self)) {
const change_record *old = get_old_record(self, c);
const change_record *old = get_old_record(self, chr);
if (old->category_changed == 0) {
/* unassigned */
Py_RETURN_FALSE;
}
}

return PyBool_FromLong(_PyUnicode_IsXidContinue(c));
return PyBool_FromLong(_PyUnicode_IsXidContinue(chr));
}

/*[clinic input]
Expand Down
2 changes: 1 addition & 1 deletion Objects/unicodectype.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

#include "Python.h"
#include "pycore_unicodedata.h" // _PyUnicode_IsXidStart, _PyUnicode_IsXidContinue
#include "pycore_unicodedata.h" // export _PyUnicode_IsXidStart(), _PyUnicode_IsXidContinue()

#define ALPHA_MASK 0x01
#define DECIMAL_MASK 0x02
Expand Down
Loading