Skip to content

[mypyc] Add librt.strings.isidentifier codepoint primitive#21522

Open
VaggelisD wants to merge 1 commit into
python:masterfrom
VaggelisD:librt-strings-isidentifier
Open

[mypyc] Add librt.strings.isidentifier codepoint primitive#21522
VaggelisD wants to merge 1 commit into
python:masterfrom
VaggelisD:librt-strings-isidentifier

Conversation

@VaggelisD
Copy link
Copy Markdown
Contributor

5th PR of #21418

True if a codepoint can start a valid identifier (XID_Start, per
PEP 3131). The ASCII fast path covers `[A-Za-z_]` inline; non-ASCII
codepoints round-trip through PyUnicode_FromOrdinal +
PyUnicode_IsIdentifier so the answer matches str.isidentifier on a
1-character string.

The non-ASCII path is the first allocating helper in this series, so
its body lives out-of-line in codepoint_extra_ops.c (it would otherwise
be emitted as a separate copy in every translation unit that includes
the header). On OOM it swallows the exception via PyErr_Clear() and
returns False, which keeps the function ERR_NEVER. Documented at the
call site so callers don't get a surprising silent failure.

Stack: depends on the librt.strings.isspace primitive.
@VaggelisD VaggelisD force-pushed the librt-strings-isidentifier branch from add1d44 to 283b2f8 Compare May 21, 2026 07:42
@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants