Skip to content

Spell a parameter name Python can take, ASCII or not - #37

Open
CNSeniorious000 wants to merge 1 commit into
mainfrom
spell-unicode-parameter-names
Open

Spell a parameter name Python can take, ASCII or not#37
CNSeniorious000 wants to merge 1 commit into
mainfrom
spell-unicode-parameter-names

Conversation

@CNSeniorious000

Copy link
Copy Markdown
Owner

paramName tested /^[A-Za-z_][A-Za-z0-9_]*$/. Python's identifier rule is XID, so a parameter named 路径 was folded into **kwargs — while the kernel, which validates the same name with inspect.Parameter, bound it as a real keyword parameter. The two halves already disagreed, and the block was the poorer one, for exactly the catalogues most likely to carry such a name.

 async def odd(
     *,
-    **kwargs: Any  # spell as dict keys: "路径", "Ω"
+    路径: str,
+    Ω: int = ...,
 )

def f(*, 路径: str) compiles, and inspect.Parameter('路径') is accepted — checked, not assumed.

The second condition, which is not optional

const isPyIdentifier = (name) => /^[\p{XID_Start}_]\p{XID_Continue}*$/u.test(name) && name.normalize('NFKC') === name

XID alone is not the rule the tokeniser applies. Source is NFKC-normalised before it is read, so a name that passes str.isidentifier() can still be un-spellable:

>>> 'fi'.isidentifier(), unicodedata.normalize('NFKC', 'fi')
(True, 'fi')
>>> exec("def f(*, fi=1, **kw): return locals()", ns); ns['f'](=2)
{'fi': 2, 'kw': {}}
>>> ast.parse("def g(*, fi: int = 0): pass").body[0].args.kwonlyargs[0].arg
'fi'

Spelled, would send the tool a key called fi — one it never declared — and the call would fail as though the tool were broken. Same for the fullwidth , which binds x. Those stay folded; 路径 and Ω are NFKC-stable and get spelled.

Verification

node test/smoke.js passes, and the new fixture's fence goes through python3 -c compile(...) so the emitted names are checked as source, not just as strings. Both conditions were mutation-checked separately:

mutation which assertion fails
back to /^[A-Za-z_][A-Za-z0-9_]*$/ an NFKC-stable non-ASCII name is spelled
XID kept, .normalize('NFKC') guard dropped an NFKC-unstable one folds even though Python calls it an identifier

Note

Scoped to the parameter path. isUsableName — tool names, imports, module names — stays ASCII: that one reaches import lines and dsh's class naming, so it deserves its own change rather than riding along. And the kernel's inspect.Parameter accepts today, which means <tool>? can still show a parameter no source can call; exotic enough that no live catalogue reaches it, but it is the same trap one level down.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @CNSeniorious000, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 17 hours by commenting @sourcery-ai review. Upgrade to get a review now.

Repository owner deleted a comment from chatgpt-codex-connector Bot Sep 1, 2026
Repository owner deleted a comment from coderabbitai Bot Sep 1, 2026
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.

1 participant