Skip to content

Support most Python 2 syntax back to 2.3#275

Closed
thatch wants to merge 14 commits intoInstagram:mainfrom
thatch:syntax-2.0
Closed

Support most Python 2 syntax back to 2.3#275
thatch wants to merge 14 commits intoInstagram:mainfrom
thatch:syntax-2.0

Conversation

@thatch
Copy link
Copy Markdown
Contributor

@thatch thatch commented Mar 27, 2020

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:

                                                  23 24 25 26 27 30 31 32 33 34 35 36 37 38
examples/py27-0024-as-keyword.py                  o. o. o  .. .. .. .. .  .. .  .. .. .. .. 
examples/py30-0004-unpacking-args1.py             o. o. o  o. o. .. .. .  .. .  .. .. .. .. 
examples/py30-0013-kwargs-after-star.py           .o .o .  oo oo oo oo o  oo o  oo oo oo oo 
examples/py30-0018-except-as.py                   .o .o .  oo oo oo oo o  oo o  oo oo oo oo 
examples/py30-0023-relative-imports1.py           .o .o o  oo oo oo oo o  oo o  oo oo oo oo 
examples/py30-0023-relative-imports2.py           .o .o o  oo oo oo oo o  oo o  oo oo oo oo 

Both relative-imports and except-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.

                                                  23 24 25 26 27 30 31 32 33 34 35 36 37 38
examples/py30-0030-int-literals1.py               oo oo o  oo oo .. .. .  .. .  .. .. .. .. 
examples/py30-0030-int-literals2.py               oo oo o  oo oo .. .. .  .. .  .. .. .. .. 
examples/py30-0030-int-literals3.py               oo oo o  oo oo .. .. .  .. .  .. .. .. .. 
examples/py30-0030-int-literals4.py               .. .. .  oo oo oo oo o  oo o  oo oo oo oo 
examples/py30-0030-int-literals5.py               .. .. .  .. .. .. .. .  .. .  .. oo oo oo 
Legend:
 green header means will test with libcst

 first result is python, second [optional] result is libcst
 o   parses
 .   does not parse

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

$ ../libcst-venv/bin/pyre
 ƛ No type errors found
$ tox -e py36
...
py36 run-test: commands[0] | python -m unittest
...
Ran 1687 tests in 85.662s

OK (skipped=3, expected failures=2)

This is relevant to #184

Loading
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.

5 participants