fix: Specify Python str semantics for character classification functions - #177
Open
mwiebe wants to merge 2 commits into
Open
fix: Specify Python str semantics for character classification functions#177mwiebe wants to merge 2 commits into
mwiebe wants to merge 2 commits into
Conversation
The isdigit/isalpha/isalnum/isspace/isupper/islower descriptions in RFC
0006 and the 2026-02 Expression Language spec did not say which
character-class convention applies, and implementations diverged:
openjd-rs used Rust char predicates, making isdigit ASCII-only while
isalnum was Unicode-wide, so isdigit('\u0663') and isalnum('\u0663')
disagreed (openjd-rs issue #309).
Clarify that these functions have exactly the semantics of the Python
str methods of the same name over the Unicode Character Database,
document the cased-character rule for isupper/islower and the
isalnum-vs-isalpha/isdigit relationship, and add a conformance test
covering Unicode inputs where the conventions differ.
Signed-off-by: Mark <399551+mwiebe@users.noreply.github.com>
Follow-up to the character classification clarification: the title and capitalize descriptions had the same ambiguity, and implementations diverged the same way (word boundaries by alphanumeric-ness instead of cased-ness, uppercase instead of titlecase mappings, no Final_Sigma context rule). Clarify both function rows and the section note in RFC 0006 and the 2026-02 Expression Language spec, and extend the Unicode conformance test with title/capitalize cases covering digit word boundaries, titlecase digraph mappings, sharp-s expansion, and final sigma. Signed-off-by: Mark <399551+mwiebe@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: Specify Python str semantics for character classification functions
Description of the change. What is being added or fixed?
RFC 0006 and the 2026-02 Expression Language spec describe
isdigit,isalpha,isalnum,isspace,isupper, andislowerwith one-linesummaries ("True if all characters are digits...") that don't say which
character-class convention applies. Every language draws different lines
through Unicode — Rust's
Alphabeticproperty is a superset of Python'sL*categories, Rust has no notion ofNumeric_Type, and so on — soimplementations diverged: openjd-rs used Rust's
charpredicates, whichmade
isdigitASCII-only whileisalnumwas Unicode-wide, and the twocontradicted each other for characters like
'٣'(U+0663 ARABIC-INDICDIGIT THREE). Reported as
openjd-rs#309.
This PR:
exactly the semantics of the Python
strmethods of the same name overthe Unicode Character Database, with the specific Unicode properties named
per function.
isalnumis strictly broader thanisalpha OR isdigit(Numeric_Type=Numeric characters like½), and thecased-character rule for
isupper/islower(uncased characters areignored; titlecase characters are cased but neither upper nor lower).
implementations aren't broken by UCD updates.
expr2.2.4--string-classification-unicode) with21 assertions on characters where the conventions differ, using
\uXXXXescapes so the file stays ASCII. The test fails against openjd-rs
mainand passes against the fix in the companion PR.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.