Skip to content
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-654: except* #571

Merged
merged 4 commits into from
Dec 29, 2021
Merged

implement PEP-654: except* #571

merged 4 commits into from
Dec 29, 2021

Conversation

zsol
Copy link
Member

@zsol zsol commented Dec 23, 2021

Summary

This PR adds support for the new grouped exception handling mechanism introduced by PEP-654. The only significant difference between AST and this CST implementation is a new ExceptStarHandler type, which differs from ExceptHandler in:

  • requiring the type attribute to be always present (it can't be None)
  • owning the whitespace between the except keyword and the *

The new syntax can only be parsed by the Rust parser (currently needing LIBCST_PARSER_TYPE=native environment variable).

Test Plan

  • unit tests
  • round-trip tests

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 23, 2021
@zsol zsol requested a review from stroxler December 23, 2021 19:03
@zsol
Copy link
Member Author

zsol commented Dec 23, 2021

@stroxler xmas treat for you :)

@codecov-commenter
Copy link

codecov-commenter commented Dec 23, 2021

Codecov Report

Merging #571 (d2386a6) into main (9c13ca5) will increase coverage by 0.03%.
The diff coverage is 98.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #571      +/-   ##
==========================================
+ Coverage   94.62%   94.65%   +0.03%     
==========================================
  Files         240      240              
  Lines       23389    23579     +190     
==========================================
+ Hits        22132    22319     +187     
- Misses       1257     1260       +3     
Impacted Files Coverage Δ
libcst/__init__.py 91.30% <ø> (ø)
libcst/matchers/_return_types.py 100.00% <ø> (ø)
libcst/_nodes/statement.py 96.15% <97.05%> (+0.05%) ⬆️
libcst/_typed_visitor.py 96.94% <98.95%> (+0.04%) ⬆️
libcst/_nodes/tests/test_try.py 100.00% <100.00%> (ø)
libcst/matchers/__init__.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c13ca5...d2386a6. Read the comment docs.

Copy link
Contributor

@stroxler stroxler left a comment

Choose a reason for hiding this comment

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

LGTM, I left a couple comments.

The big thing I skipped was the matcher code, I can take a look at that but it will require some self-training so I figured I'd let you decide whether it's worth it first.

libcst/_nodes/statement.py Show resolved Hide resolved
libcst/_nodes/statement.py Show resolved Hide resolved
libcst/matchers/__init__.py Show resolved Hide resolved
native/libcst/src/nodes/statement.rs Show resolved Hide resolved
@@ -498,6 +499,13 @@ parser! {
make_try(kw, b, ex, el, f)
}

// Note: this is separate because TryStar is a different type in LibCST
rule try_star_stmt() -> TryStar<'a>
Copy link
Contributor

Choose a reason for hiding this comment

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

The official grammar has this as a variant under try_stmt. We're sure it's worth diverging? I can see some value in it since the actual AST node variant is different, but there's a price we'll pay keeping things in sync for every rule that diverges.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not 100% sure it's worth it, I was a bit lazy and wanted to avoid an additional enum layer just so we can have a single rule.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh are the rules tied more tightly to types in the rust PEG library than in C?

In CPython it's a single PEG variant, but two different AST types still

@zsol zsol merged commit 67db039 into main Dec 29, 2021
@zsol zsol deleted the except-star branch December 29, 2021 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants