Spell a parameter name Python can take, ASCII or not - #37
Open
CNSeniorious000 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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.
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.
paramNametested/^[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 withinspect.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, andinspect.Parameter('路径')is accepted — checked, not assumed.The second condition, which is not optional
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:Spelled,
fiwould send the tool a key calledfi— one it never declared — and the call would fail as though the tool were broken. Same for the fullwidthx, which bindsx. Those stay folded;路径andΩare NFKC-stable and get spelled.Verification
node test/smoke.jspasses, and the new fixture's fence goes throughpython3 -c compile(...)so the emitted names are checked as source, not just as strings. Both conditions were mutation-checked separately:/^[A-Za-z_][A-Za-z0-9_]*$/.normalize('NFKC')guard droppedNote
Scoped to the parameter path.
isUsableName— tool names, imports, module names — stays ASCII: that one reachesimportlines and dsh's class naming, so it deserves its own change rather than riding along. And the kernel'sinspect.Parameteracceptsfitoday, 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.