Commit graph

55 commits

Author SHA1 Message Date
jimmylai
c023fa7c4c
[typing] enable Pyre strict mode by default (#313)
Co-authored-by: Jimmy Lai <jimmylai@fb.com>
2020-06-12 18:24:18 -07:00
Tim Hatch
dbcb5bed99
Improve default-version selection logic (#306)
* Add Python 3.9 to tox envlist

* Require newer typing_extensions for 3.9

For simplicity, use the new version in all cases.

* Improve default-version selection to work on 3.9

While were at it, improve the code to work with a likely 3.10 by
allowing multiple digits for minor version.
2020-06-10 10:29:58 -07:00
Tim Hatch
8053cdbc6e [parsing 3.1] with multiple items 2020-03-12 08:45:18 -07:00
Tim Hatch
0bde0ce60c [parsing 3.3] disallow u-prefix strings from 3.0 to 3.2 2020-03-12 08:45:18 -07:00
Tim Hatch
f17bde3fe2 [parsing 3.3] yield from (PEP 380) 2020-03-12 08:45:18 -07:00
Tim Hatch
21ca166c15 [parsing 3.3] Unpacking generalizations (PEP 448) 2020-03-12 08:45:18 -07:00
Tim Hatch
a65cb06f3a [parsing 3.3] async def (PEP 492) 2020-03-12 08:45:18 -07:00
Tim Hatch
9d0a2be845 [parsing 3.3] Matrix multiply (PEP 465) 2020-03-12 08:45:18 -07:00
Tim Hatch
2a3703ec0a Simplify allowed python_versions, add 3.3 2020-03-12 08:45:18 -07:00
Tim Hatch
0c7d8b42ba Plumb through future_imports 2020-03-12 08:45:18 -07:00
Tim Hatch
522eb5ee0c Add detecting future imports to config.
Several of the python 2 features are gated on these in addition to
version (like `with_statement`), and a refactoring tool like Bowler
commonly needs this information anyway.
2020-03-12 08:45:18 -07:00
Tim Hatch
5651bc94db Silence convert_argslist is too complex 2020-03-05 06:35:39 -08:00
Jennifer Taylor
fdd5cbbfe6 Implement parsing of posonly param indicator ('/'). This brings us to full 3.8 compatibility. 2020-01-17 10:57:48 -08:00
Jennifer Taylor
f45c57342b Support f{x=} debugging syntax that was added to f-strings in 3.8. 2020-01-16 13:13:54 -08:00
Jennifer Taylor
91387f5f2f Remove deprecated default_params attribute. 2020-01-08 17:18:41 -08:00
Jimmy Lai
8887c3f3b8 remove unused type vars. 2020-01-08 12:01:22 -08:00
Jimmy Lai
495b65206c ignore typing errors 2019-12-17 14:27:53 -08:00
Jennifer Taylor
c9b10fe427 Deprecate "default_params" on Parameters in preparation for 3.8 position-only params. 2019-12-03 10:56:01 -08:00
Jennifer Taylor
0f25f5ce2c Implement parsing of the walrus operator.
This hooks the operator up to a parser, and adds it into appropriate spots in the grammar given 3.8's official grammar specification.
2019-10-24 15:25:21 -07:00
Jennifer Taylor
b3253de9b8 Update black to git commit that fixes 3.8 support. 2019-10-24 15:25:21 -07:00
Jennifer Taylor
7703d4b93d Add bugfix grammar changes for Python 3.8. 2019-10-24 15:25:21 -07:00
Jennifer Taylor
57860f3d76 Fix trailing newline detection around continuation.
If you have such a program like "pass\\\n", this is technically a program without a trailing newline, since line continuations are defined as being a `\` followed by a newline. We were misdetecting this as having a trailing newline, thus making it impossible to parse the continuation. Add some tests to verify this behavior and then fix the problem.

Note that this was found via hypothesis.
2019-10-21 13:24:25 -07:00
Jennifer Taylor
48ba3b0849 Remove parsing Subscript slice directly into Index/Slice.
This makes sure we always wrap elements in a SubscriptElement, even when there
is only one element. This makes things more regular while still being backwards
compatible with existing creation. The meat of this is in two halves, which can't
be split due to not wanting to break the build between commits. The first half
is just the changes to the parser and updates to tests. This includes a test to
be sure we can still render code that uses old construction types. The second half
is changes to codegen which made assumptions about `Subscript` and demonstrates
the need to make this change in the first place. This includes a fix to
`CSTNode.with_deep_changes` type to make it more correct and also more usable in
transforms without additional type assertions.
2019-10-18 13:40:10 -07:00
Jennifer Taylor
e533e6ae73 Rename ExtSlice to SubscriptElement in anticipation of further fitxes.
This is somewhat complicated by the fact that we need to not just allow
construction of nodes/matchers using `ExtSlice` still for backwards compatibility,
but we also need to be able to call `visit_ExtSlice` and `leave_ExtSlice` on
old visitors even though the new node is named `SubscriptElement`. The
construction/instance check/matching side of things will work since internally we
refer to everything as `SubscriptElement` and alias `ExtSlice` to this everywhere,
but for string-based function lookup, we need to get a little more clever and make
the default `visit_SubscriptElement` delegate onward to `visit_ExtSlice` so that
either form works.

This can all be removed again once we're past the deprecation period for ExtSlice.
2019-10-16 16:00:27 -07:00
Jennifer Taylor
8a8ea4b27b Upgrade Pyre to 0.32.
This fixes a TODO, removes several ignore statements and most importantly, addresses a massive speed regression triggered by importing matchers.
2019-10-04 11:05:37 -07:00
Jennifer Taylor
a6bdc9d03d Add test case for uniqueness of resulting tree when parsing. 2019-09-25 12:36:33 -07:00
Jennifer Taylor
fb4785cfa1 Bump pyre version to 0.0.30.
This introduces a few new gotchas (namely attribute access and a bug with
Union[Callable]), but it also removes a whole host of pyre-fixmes and gets us
updated to a release of pyre that came out after May.
2019-09-25 12:04:33 -07:00
Jennifer Taylor
fc430343b5 Fix internal underscore convention.
Standardize on the convention that private modules (those we don't expect people to directly import) are prefixed with an underscore. Everything under a directory/module that has an underscore is considered private, unless it is re-exported from a non-underscored module. Most things are exported from libcst directly, but there are a few things in libcst.tool, libcst.codegen and libcst.metadata that are namedspaced as such.
2019-09-17 13:52:42 -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
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
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
b232547826
[typing] refactor TypeVar CSTNodeT for consistency and reusability (#54) 2019-08-29 21:30:34 -07:00
Jennifer Taylor
9a90fda8c3 Document additional caveats with parse_statement and parse_expression. 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
Benjamin Woodruff
aac5103592 Add PartialParserSyntaxError, simplify ParserSyntaxError
Because the parser conversion functions may not understand their current
position in the code, we instead need to construct a `ParserSyntaxError`
without the current line and column information, filling it in later.

Originally I did this by allowing ParserSyntaxError to be partially
initialized, but this wasn't very type-safe, and required some ugly
assertions.

Instead, I now construct and raise a PartialParserSyntaxError. The
BaseParser class is responsible for catching that partial error object
and constructing a full ParserSyntaxError.
2019-08-22 13:35:11 -07:00
Benjamin Woodruff
283a736173 Make conversion functions use ParserSyntaxError
For anything that's not an internal logic error, conversion functions
should raise a ParserSyntaxError.

Internal logic errors should probably use an AssertionError or an assert
statement, but that's not as important and is out of scope for this PR.
2019-08-22 13:35:11 -07:00
Benjamin Woodruff
e9567a08c0 Add tests to the parser for syntax errors
This tries to test all the ways a ParserSyntaxError can be thrown.
2019-08-22 13:35:11 -07:00
Benjamin Woodruff
636cad6e6c Raise a ParserSyntaxError on mismatched braces
If we had more close braces than open braces, we used to raise an
IndexError due to an empty stack. This fixes that bug.
2019-08-22 13:35:11 -07:00
Benjamin Woodruff
2459ba0aa0 Make ParserSyntaxError more generic (#24)
This removes the hard-coded logic about encountered/expected, and moves
it into a separate helper method.

Line and column can now be initialized lazily. We'll use this later to
raise `ParserSyntaxError`s inside of conversion functions, backfilling
the positions inside `_base_parser`, since conversion functions don't
always have access to position information.
2019-08-22 13:35:11 -07:00
Benjamin Woodruff
53a7c782d4 Improve PartialParserConfig's documentation
Adds details about how various configuration options can be used, and
updates some details to reflect reality (e.g. we don't currently infer
the python version from your execution environment).
2019-08-19 17:09:55 -07:00
Benjamin Woodruff
821a613c46 Raise an exception on unsupported python_version
We only support parsing code as 3.7 right now.

This raises a descriptive error message if we receive an unsupported
version number, instead of silently trying to use it with the tokenizer
and failing in potentially strange ways.
2019-08-19 17:09:55 -07:00
Jennifer Taylor
d3ce7da7ce Drop annotation indicator attribute.
We pass down the correct default annotation indicator to use in 100% of code rendering places, so this becomes a useless bit of initialization. We already set this to a sentinel by default, and the only thing that having an explicit str gives us is the inability to copy an annotation from a param to a return or vice versa. So, out it goes. This means we can't render Annotation by itself, so the test that was using this behavior is out too.
2019-08-05 17:13:17 -07:00
Jennifer Taylor
9ca3d39fb6 Rename Ellipses to Ellipsis to match AST and Python stuff. 2019-08-02 17:17:38 -07:00