-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: Python-Rust combining char diff in isalnum #7612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
youknowone
merged 2 commits into
RustPython:main
from
joshuamegnauth54:isalnum-combining-character
Apr 17, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,15 @@ | |
| # assert "DZ".title() == "Dz" | ||
| assert a.isalpha() | ||
|
|
||
| # Combining characters differ slightly between Rust and Python | ||
| assert "\u006e".isalnum() | ||
| assert not "\u0303".isalnum() | ||
| assert not "\u006e\u0303".isalnum() | ||
| assert "\u00f1".isalnum() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it may be worth opening a PR for CPython to test those changes to ensure there's no regression on their end as well (it will get to us as well) |
||
| assert not "\u0345".isalnum() | ||
| for raw in range(0x0363, 0x036F): | ||
| assert not chr(raw).isalnum() | ||
|
|
||
| s = "1 2 3" | ||
| assert s.split(" ", 1) == ["1", "2 3"] | ||
| assert s.rsplit(" ", 1) == ["1 2", "3"] | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 96
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 271
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 675
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 668
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 598
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 2247
🌐 Web query:
U+093F DEVANAGARI VOWEL SIGN I Unicode canonical combining class properties💡 Result:
The Unicode character U+093F DEVANAGARI VOWEL SIGN I has Canonical Combining Class 0 (Not Reordered).
Citations:
🌐 Web query:
U+0303 combining tilde canonical combining class general category💡 Result:
The Unicode character U+0303 (Combining Tilde) has: - Canonical Combining Class: Above (230) - General Category: Nonspacing Mark (Mn)
Citations:
🌐 Web query:
CPython str.isalnum() implementation definition Unicode categories💡 Result:
The CPython implementation of str.isalnum determines if all characters in the string are alphanumeric (letters or numbers) and the string is non-empty. It uses Unicode general categories: a character is alphanumeric if it is alphabetic (general categories L: Letter, specifically "Lm", "Lt", "Lu", "Ll", or "Lo") OR numeric (specifically Decimal_Digit "Nd", though isalnum combines alpha or digit properties). From official documentation: Alphabetic characters are those with general category property being one of "Lm", "Lt", "Lu", "Ll", or "Lo". For isdigit, numeric characters are those with Numeric_Type=Digit (Nd), Decimal (Nd), or Numeric (No, Nl). isalnum is effectively isalpha or isdigit. The C implementation is in Objects/unicodectype.c using _PyUnicode_TypeRecord flags: ALPHA_MASK (0x01) for categories Ll/Lu/Lt/Lo/Lm, and DIGIT_MASK or DECIMAL_MASK for numeric. The function likely checks (ctype->flags & (ALPHA_MASK | DIGIT_MASK)) != 0, though exact isalnum function not directly shown, but follows from isalpha and isdigit patterns and Py_UNICODE_ISALNUM macro. For bytes.isalnum, it uses Py_ISALNUM from pyctype.h table for ASCII. Sources confirm via unicodedata lookups and generated tables from Unicode data.
Citations:
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 327
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 601
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 708
CanonicalCombiningClass::NotReorderedfiltering is incomplete for CPython parity.CPython defines
str.isalnum()asisalpha() || isdecimal() || isdigit() || isnumeric(), whereisalpha()accepts only Unicode letter categoriesLm/Lt/Lu/Ll/Lo. Rust'schar::is_alphanumeric()is broader, includingAlphabeticproperty which covers combining marks. Unicode class-zero (NotReordered) marks include spacing combining marks like U+093F (DEVANAGARI VOWEL SIGN I), which has categoryMcand combining_class=0. The current filter admits such marks despite CPython rejecting them. Tests cover only non-class-zero combining marks (U+0303/U+0345/U+0363..U+036F, all with combining_class=230 or 240), missing this gap. Switch to a CPython-compatible category check (is_letter_category(L*) || is_digit_category(N*)) and add a regression test for U+093F. The mirror predicate incrates/sre_engine/src/string.rs:444-452(which has a TODO comment) should be updated in lockstep to keepstr.isalnum()and\waligned.🤖 Prompt for AI Agents