-
Notifications
You must be signed in to change notification settings - Fork 192
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
Support most Python 2 syntax back to 2.3 #275
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #275 +/- ##
==========================================
- Coverage 94.30% 93.81% -0.49%
==========================================
Files 232 233 +1
Lines 22442 23053 +611
==========================================
+ Hits 21163 21627 +464
- Misses 1279 1426 +147 ☔ View full report in Codecov by Sentry. |
For completeness, here are future import not covered in the
|
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.
Did a run-through but would defer to @jimmylai for approval, my LibCST is a bit rusty.
Thanks for this work!
Did another more careful run-through, this looks pretty good to me. In an ideal world I'd prefer to bump the test coverage up a bit; a number of the new Py2 nodes don't really get validation or codegen exercised at all by the test suite, and overall this brings test coverage down. Seems like your change-examples repo goes a long way to giving confidence in the correctness here, but I wish we could get more of that confidence built in to LibCST's own test suite so that future changes are validated too. But I'm also not that invested in Py2, either, so not going to block on that :) Thanks for all the hard work here! @jimmylai do you want me to hold off on merging so you can review this too, or just go ahead? |
I can review this today. Maybe just wait a bit for me. |
I will work on increasing coverage, if you want to wait a day... |
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.
A couple of new Node types (especially Py2Raise
and Py2ExecTarget
) and some new functions in statement.py
don't have good test coverage.
https://codecov.io/gh/Instagram/LibCST/pull/275/diff
For documentation page, https://libcst.readthedocs.io/en/latest/nodes.html
(which is generated by https://github.com/Instagram/LibCST/blob/621d9a949a57a9100b7f2d1465ebd32aaeddb05c/docs/source/nodes.rst),
we can probably have another doc page for Python2 to prevent confusion. It's also better to include the Python versions availability in each node types in the doc by integrating information from
https://github.com/thatch/python-grammar-changes
That can be an enhancement as follow up PRs.
Otherwise looks great. Thanks for working on this.
@@ -13,3 +13,4 @@ build/ | |||
.coverage | |||
.hypothesis/ | |||
.pyre_configuration | |||
pip-wheel-metadata |
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.
How is this file generated?
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.
I don't remember exactly, but pypa/pip#6213 says "pip wheel ." does it, and that seems reasonable.
libcst/_nodes/statement.py
Outdated
expr: BaseExpression | ||
target: Optional[Py2ExecTarget] | ||
|
||
whitespace_after_exec: SimpleWhitespace = SimpleWhitespace.field(" ") | ||
|
||
semicolon: Union[Semicolon, MaybeSentinel] = MaybeSentinel.DEFAULT |
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.
Those attributes miss some detailed Sphinx inline comments like other node type.
I'll try to rebase this over the holidays. |
If this isn't of the expected type, the `.value` reference later would fail.
From testing, PEP 401 does not work in source files, only in the REPL, so this does not need to check for `barry_as_FLUFL`. Since the tokenization is unambiguous (`<`+`>` is not a valid sequence otherwise), we include it unconditionally.
Functionally this is an additional syntax to run `repr()`.
@jimmylai I think this is ready for another review. I fixed some docs and tests, and pyre is passing locally (but I don't entirely believe that). Is there an easy way to kick off a circleci run? |
Circle CI shows all tests were passed. It automatically runs whenever you push an update to a PR. Yeah, I'll do another round of review. |
Some functions are not covered by tests. Can you add some tests?
https://codecov.io/gh/Instagram/LibCST/pull/275/diff?src=pr&el=tree#diff-bGliY3N0L19faW5pdF9fLnB5 Did you try running this run on our large codebase through Fixit rules and unit tests? That can help us identify some issue from major changes like this PR. |
Hi @thatch! Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours needs attention. You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Summary
This now parses a good amount of real-world
setup.py
code, and I've validated back to 2.3 (the earliest version I have handy). It passes most of python-grammar-changes with only a few remaining failures:Both
relative-imports
andexcept-as
are important.unpacking-args
is a feature I haven't seen used since about 2004. The other two are for additional strictness to reject bad code, but are not necessary for my immediate needs.Integer validation is reasonably strict at parse time, and handles both the octal changes and
L
suffix change.New classes have
Py2
-prefixed names, to make it a conscious decision for people so they don't accidentally using them when constructing trees by hand.Test Plan
This is relevant to #184