Fix isalpha/isalnum and regex \w to use Unicode General Category instead of Alphabetic derived property#7520
Draft
Fix isalpha/isalnum and regex \w to use Unicode General Category instead of Alphabetic derived property#7520
isalpha/isalnum and regex \w to use Unicode General Category instead of Alphabetic derived property#7520Conversation
… \\w for Mn characters Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/6f573a91-8811-486c-933d-7ba9a9067643 Co-authored-by: youknowone <[email protected]>
Copilot
AI
changed the title
[WIP] Fix isalnum function to align with CPython standards
Fix Mar 27, 2026
isalpha/isalnum and regex \w to use Unicode General Category instead of Alphabetic derived property
| assert not "\u0345".isalnum(), "isalnum should not match Mn category characters" | ||
|
|
||
| import re | ||
| assert not re.match(r"\w", "\u0345"), r"\w should not match U+0345 (category Mn)" |
Contributor
There was a problem hiding this comment.
[reviewdog-suggester] reported by reviewdog 🐶
Suggested change
| assert not re.match(r"\w", "\u0345"), r"\w should not match U+0345 (category Mn)" | |
| assert not re.match(r"\w", "\u0345"), r"\w should not match U+0345 (category Mn)" |
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.
Rust's
char::is_alphabetic()/char::is_alphanumeric()use the Unicode Alphabetic derived property, which is a superset of the Unicode letter categories and includes some non-spacing marks (Mn). CPython'sstr.isalpha()andstr.isalnum()are defined strictly by General Category membership (letters: Lu/Ll/Lt/Lm/Lo; numbers: Nd/Nl/No), causing divergence for characters like U+0345 (COMBINING GREEK YPOGEGRAMMENI, category Mn).Changes
crates/vm/src/builtins/str.rs: Replacechar::is_alphabetic()/char::is_alphanumeric()inisalpha()andisalnum()with explicitGeneralCategorychecks (L* forisalpha; L* + Nd/Nl/No forisalnum).crates/sre_engine/src/string.rs: Apply the same fix tois_uni_alnum()(used for\win regex); remove the pre-existing// TODO: check with cpythonnote.crates/sre_engine/Cargo.toml: Addunic-ucd-categoryworkspace dependency.extra_tests/snippets/builtin_str_unicode.py: Add regression assertions for U+0345 acrossisalpha,isalnum, andre.match(r"\w", ...).Original prompt
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.