Indentation for match-case statements (Python 3.10 - Structural Pattern Matching - PEP634, PEP635, PEP636) #6
No reviewers
Labels
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
codemirror/lang-python!6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/pep634-matchcase-indent"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Lezer already supports the match-case grammer in Python3.10 PEP634, relevant commit is this. However, lang-python does not support indent for match case block yet.
This PR implements such support. Besides, I re-organized the python indent module with heavy documents to make the logic flow more straight-forward. There's no logging and the indent processing logic is recursive in nature. Such docs should help future development a lot.
That's not really a good idea—it forces me to review a bunch of spurious changes and reformats. Any way you could separate out the match case support without rewriting this entire file?
I've finished clean up and now the diff is more clear: only two match-case statements added to
indentNodeProp, together with clear variable names (no logic changes) of the two small util functions.I'm aware that working with legacy codes it's best to keep change small but the existing implementation of the function is kind-of tricky. I genuinely think making them easier (for future maintainers) to follow could be a right choice. Besides, extensive unit-tests should help ensure there's no degradation. I've tested old/new version on those tests.
Do this and
deindentingPatternhandle false positive case ofcase = 123? This is becausecaseis a soft keyword and can be used as a variable name (compared toexcept,elif, etc).Good catch. I've updated so that it only trigger "indentOnInput" action and properly de-indent following
skw<case>grammer, like in below example:Rationale is that as of typing to
Therefore, we might need to change the de-indenting pattern regex from simply "case " with a trailing space to "case :"
You're still adding semicolons (in a project that doesn't use them), changing
lettoconst, and making other spurious changes. This is a bit like if I'd come into your house to arrange the furniture so that it looks the way I like—this being your house, I shouldn't come in an rearrange stuff to my taste.This package is not legacy code.
Thanks for the clarification. Apologize for dramatic change earlier.
Updated PR so it's now a single, isolated change focusing on the PEP634 feature itself.
Nice! This looks like a solid, clean pull request now. Thanks for implementing that. Merging.