-
Notifications
You must be signed in to change notification settings - Fork 196
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
Implement PEP-634 - Match statement #568
Conversation
Codecov Report
@@ Coverage Diff @@
## main #568 +/- ##
==========================================
+ Coverage 94.65% 94.72% +0.06%
==========================================
Files 240 241 +1
Lines 23579 24635 +1056
==========================================
+ Hits 22319 23335 +1016
- Misses 1260 1300 +40
Continue to review full report at Codecov.
|
@zsol did you want me to review this as well? |
Sure, if you have time!
…On Wed, 29 Dec 2021, 01:36 Steven Troxler, ***@***.***> wrote:
@zsol <https://github.com/zsol> did you want me to review this as well?
—
Reply to this email directly, view it on GitHub
<#568 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAQJNCIKXMNP2FH5BDA6EDUTJQ2LANCNFSM5KU7X4BA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hey! First of all, amazing work, pulling this off in such a short time. I was testing this branch on my own test cases, and I've found a really peculiar bug: # pylint: for some reason, having a comment starting with `pylint: ` is important for this bug to show up
match x:
case y.z:
pass This is what happens when I try to parse this: [...]
E libcst._exceptions.ParserSyntaxError: Syntax Error @ 4:14.
E parser error: error at 4:13: expected one of (, .
E
E case y.z:
E ^
venv3/lib/python3.10/site-packages/libcst/_parser/entrypoints.py:55: ParserSyntaxError If I remove the comment on top, change |
Hey @tushar-deepsource thanks for trying this out! Can confirm I can repro the problem, but AFAICT the issue is with the |
That seems to have fixed every edge case that I have in my codebase. Just one thing remains: something to do with trailing indent whitespace: Python 3.10.0
>>> import libcst
>>> code = '''\
... if x == type(y):
... pass
... ''' # This indent whitespace is important
>>> libcst.parse_statement(code)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../libcst/_parser/entrypoints.py", line 138, in parse_statement
result = _parse(
File ".../libcst/_parser/entrypoints.py", line 55, in _parse
return parse(source_str)
libcst._exceptions.ParserSyntaxError: Syntax Error @ 3:5.
parser error: error at 3:4: expected one of (, *, +, -, ..., AWAIT, DEDENT, False, NAME, NUMBER, None, True, [, break, continue, lambda, match, not, pass, ~
pass
^
>>> |
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.
Overall LGTM
I have a few nits on ordering that you could ignore, and I think one of the test fixtures could use more cases.
Match, | ||
MatchCase, | ||
MatchAs, | ||
MatchClass, |
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.
notes to self:
- Match is Match from Python.asdl, a variant of statement
- MatchCase is match_case from Python.asdl
- MatchPattern is presumably
pattern
type from Python.asdl - The following types don't appear to exist in Python.asdl, they are LibCST-only:
- MatchClass, MatchKeywordElement, MatchList, MatchMappingElement, MatchTuple
- Everything else is a variant of MatchPattern
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.
Just between us: I mostly used the ast
module as a reference instead of Python.asdl, the latter is not typed strongly enough for my taste
patterns: Sequence[Union["MatchSequenceElement", "MatchStar"]] | ||
|
||
#: Parenthesis at the beginning of the node | ||
lpar: Sequence[LeftParen] = field(default_factory=lambda: (LeftParen(),)) |
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.
Is the factory really needed here?
I thought they were generally necessary only for mutable containers, which tuple isn't
This PR implements the match statement in LibCST.