Commit graph

255 commits

Author SHA1 Message Date
Jimmy Lai
ec68bdb147 update import paths in Jupyter notebook 2019-09-16 19:53:22 -07:00
Jimmy Lai
213b335cd5 move metadata providers its data structures to libcst.metadata 2019-09-16 19:53:22 -07:00
Jimmy Lai
d55a8bc060 update author in Sphinx conf.py 2019-09-16 19:53:22 -07:00
Jimmy Lai
612cbb0a9e add docstring to ScopeProvider 2019-09-16 19:53:22 -07:00
Jimmy Lai
966ab81a36 add ScopeProvider document 2019-09-16 19:53:22 -07:00
Jennifer Taylor
dcf27644b5 Add support for Python 3.5
There were only grammar changes between 3.5 and 3.6, which are pretty trivial to put in. So, do that trivial bit and get us completely covered for production Python 3 versions. This could use better testing, but it is good enough as-is and we can address issues with GitHub's issue tracker.
2019-09-16 15:57:59 -07:00
Jennifer Taylor
99e69e6569 Update README.rst to include that we support parsing 3.6 as well as 3.7. 2019-09-16 15:57:59 -07:00
Jennifer Taylor
e5b28ab45b Teach LibCST to be multi-version aware.
This adds the ability to subdivide the grammar into different python versions,
as well as the ability to change the tokenizer per python version. I use this
to add support for Python 3.6 since this is a supported version we run on. This
can be used for others to add support for older or newer Python versions, regardless
of tokenizer/grammar changes.
2019-09-16 15:57:59 -07:00
Jimmy Lai
23b7b5ade2 support mypy using py.typed 2019-09-16 13:49:08 -07:00
Jimmy Lai
0182902167 Fix some typos and add watchman config for pyre incremental check 2019-09-16 13:48:34 -07:00
Jimmy Lai
58413ababf visit remaining attributes to make sure each node has a scope associated. 2019-09-13 15:43:17 -07:00
Jimmy Lai
0a07e9ac6e add docstring to _visit_comp_alike and add nested comprehension tests 2019-09-13 15:43:17 -07:00
Jimmy Lai
bd8fa91477 add basic ComprehensionScope implementation 2019-09-13 15:43:17 -07:00
Jimmy Lai
f4054b30c9 add nonlocal scope overwirte support 2019-09-13 15:43:17 -07:00
Jimmy Lai
381f3066d6 add docstring to explain `except as` special case 2019-09-13 15:43:17 -07:00
Jimmy Lai
ce5628f865 update ExpressionContext to handle AsName with STORE context 2019-09-13 15:43:17 -07:00
Jimmy Lai
096b872464 remove unused node=None 2019-09-13 15:43:17 -07:00
Jimmy Lai
64feb469c2 address review feedback 2019-09-13 15:43:17 -07:00
Jimmy Lai
61aa8a512b add global scope overwirte support 2019-09-13 15:43:17 -07:00
Jimmy Lai
cfa27215ba [metadata] add ScopeProvider for scope analysis 2019-09-13 15:43:17 -07:00
Jimmy Lai
38badee8c4 [metadata] add ScopeProvider 2019-09-13 15:43:17 -07:00
Jennifer Taylor
f1242b7a78 Fix tests failing in CI with coverage build.
I think this is a test ordering issue, since its failing to find something in cache, but it doesn't fail on my environment. So, this should be the fix.
2019-09-12 14:09:00 -07:00
Jennifer Taylor
95fabe490e Add copyright headers to all files. 2019-09-12 14:09:00 -07:00
Jennifer Taylor
f0fc5089c9 Fork relevant Parso tests into LibCST. 2019-09-12 14:09:00 -07:00
Jennifer Taylor
e972a3c9b3 Remove parso as a dependency.
We've forked parso internally, so we no longer need a dependency on it. This
exposed an unused version info function that still referenced parso, so I
deleted it.
2019-09-12 14:09:00 -07:00
Jennifer Taylor
50c5f4ecbf Fork parso's pgen2 fork into LibCST
This completes the fork of parso into LibCST's parser directory.
2019-09-12 14:09:00 -07:00
Jennifer Taylor
34767ca6c1 Fork parso's token and tokenize modules.
Fork both of these and convert internal LibCST stuff to point at them.
Removes the TODO from previous commit now that the tokenizer is in
complete agreement.
2019-09-12 14:09:00 -07:00
Jennifer Taylor
f28b0e2537 Fork Parso's utils.py
Brings a copy of utils.py internal to LibCST, rewriting our uses of it
to use our internal fork. A compatibility shim (__iter__) is currently
included to make PythonVersionInfo compatible with Parso directly.
2019-09-12 14:09:00 -07:00
jimmylai
4b714e77ee
[doc] fix wrong class name references in comprehension nodes (#62) 2019-09-12 12:09:29 -07:00
Jennifer Taylor
f9ff50047e Bump hypothesis/hypothesmith version now that https://github.com/Zac-HD/hypothesmith/issues/3 is resolved. 2019-09-10 16:57:16 -07:00
Jennifer Taylor
036cfbc765 Pin Hypothesis to work around https://github.com/Zac-HD/hypothesmith/issues/3 2019-09-09 16:02:24 -07:00
Gareth T
41af9de31d [docs] Small update and corrections to documentation. (#55) 2019-09-03 10:30:08 -07:00
jimmylai
b232547826
[typing] refactor TypeVar CSTNodeT for consistency and reusability (#54) 2019-08-29 21:30:34 -07:00
Jennifer Taylor
38d220d224 Bump version number to 0.1.2. 2019-08-29 14:25:37 -07:00
Jennifer Taylor
0d2b66a1e7 Add more documentation around attribute visitors.
Adds a bit more documentation to various pieces of attribute visitors.
Adds a section around traversal order of visitors given a tree.
2019-08-29 14:16:51 -07:00
Jennifer Taylor
ce47f864a2 Create a config_for_parsing property on Module.
This is useful when you are using `parse_expression` or `parse_statement`
to generate a tree from a source string that is meant to be later added
to an existing module. It allows you to more easily configure both of these
parser functions to output a tree which has the same defaults as the `Module`
that you previously parsed out.
2019-08-29 14:16:25 -07:00
Jennifer Taylor
9a90fda8c3 Document additional caveats with parse_statement and parse_expression. 2019-08-29 11:33:57 -07:00
Jennifer Taylor
687f47c5aa Update hypothesis tests to reflect new reality.
`parse_statement` and `parse_expresssion` aren't guaranteed to round-trip
exactly due to the fact that they don't have a wrapping Module to encapsulate
miscelaneous spacing. So, update the tests to verify that the rendered code
is identical to the original code based on the AST. Also, while I'm at it,
bump up Hypothesis's maximums in order to stress LibCST more.
2019-08-29 11:33:57 -07:00
Jennifer Taylor
ed73b0456f Allow more esoteric spacing in Import statement. 2019-08-29 11:33:57 -07:00
Jennifer Taylor
6dca3c914e Fix inability to parse certain expressions that ast.parse parses. 2019-08-29 11:33:57 -07:00
Jennifer Taylor
95f649af79 Fix incorrect round-tripping of newlines when parsing statements.
Hypothesis found that when we have a statement like `pass\r`, we detect that
`\r` is the default and parse the trailing newline as `Newline(None)`. However, when
we render the statement back out again, since we don't have a module, we construct
a default module which treats `Newline(None)` as a `\n` not a '\r'. So, when we are
parsing statements or expressions, disable auto-inferring the default newline and always
infer the default rendered newline (`\n`) so that rendering a statement/expression back
out behaves as expected.
2019-08-29 11:33:57 -07:00
jimmylai
70d6ca6513
[doc] improve metadata docs. (#50) 2019-08-28 13:41:31 -07:00
Jennifer Taylor
956460617e Codegen attribute visitors. 2019-08-28 13:28:29 -07:00
Jennifer Taylor
53fae25b7d Visit and leave attributes. 2019-08-28 13:28:29 -07:00
Jennifer Taylor
7287190e21 Pass parent down to visitor helper methods in preparation for attribute visitors. 2019-08-28 13:28:29 -07:00
Jennifer Taylor
0da658d183 Calculate necessity of MaybeSentinel/RemovalSentinel based on usage.
There are a lot of nodes that cannot be removed or converted to maybes, such as
most of the Op tokens. It would be a bit of a lie to codegen leave_* methods
that allow these nodes to be converted, only to throw a runtime error later. So,
upgrade the codegen to allow us to see whether certain nodes are used in conjunction
with a MaybeSentinel/None, or inside a Sequence, to inform ourselves as to when to
allow MaybeSentinel or RemovalSentinel.
2019-08-28 13:28:29 -07:00
Jennifer Taylor
f1e97748f2 Add a BaseStatement type.
Adds a BaseStatement type which can be used to specify in types that you can
accept either a compound statement or a simple statement line.
2019-08-28 13:28:29 -07:00
Jennifer Taylor
90e39ca4fa Add a tox environment for running codegen. 2019-08-28 13:28:29 -07:00
Jennifer Taylor
f9437f42b4 Add unit test to verify that codegen is clean.
We want to make sure that the generated function stubs stay in sync with
the node definitions. So, make a unit test that fails if codegen generates
a different file than the existing file, so that somebody modifying code
knows they need to re-run codegen.
2019-08-28 13:28:29 -07:00
Jennifer Taylor
f14b4fa37c Add codegen for visit_* and leave_* methods on CSTTransform and CSTVisitor.
This allows Pyre to typecheck returns inside visitors for us.
2019-08-28 13:28:29 -07:00