Commit graph

30 commits

Author SHA1 Message Date
zaicruvoir1rominet
ca1f81f049
Avoid raising bare Exception (#1168)
* Keep old exception messages (avoid breaking-changes for users relying on exception messages)

* Move ``get_expected_str`` out of _exceptions.py, where it does not belong, to its own file in _parser/_parsing_check.py
2025-06-07 01:53:44 -07:00
zzl
47e5ea15e1
Fix parse error message for number parsing (#724)
Co-authored-by: zzl0 <zhuzhaolong0@mail.com>
2022-08-04 11:33:26 +01:00
Zsolt Dollenstein
d9a1dc8473
Fix all type errors (#579)
* bump pyre version
* make sure CI-pyre uses working copy
* remove unused pyre suppressions
* suppress invalid decorations
* fix undefined attributes
* fix missing return annotations
* fix tuple concatenation issues
* add native stubs
* fix invalid typing of **kwargs in test_apply_type_annotations
* only install pyre on non-windows
* update test fixture to reflect changes in recent pyre versions
* suppress errors related to mismatched positions
2022-01-05 18:13:01 +00:00
Zsolt Dollenstein
c44ff0500b
Fix license headers (#560)
* Facebook -> Meta

* remove year from doc copyright
2021-12-28 11:55:18 +00:00
Zsolt Dollenstein
c02de9b718
Implement a Python PEG parser in Rust (#566)
This massive PR implements an alternative Python parser that will allow LibCST to parse Python 3.10's new grammar features. The parser is implemented in Rust, but it's turned off by default through the `LIBCST_PARSER_TYPE` environment variable. Set it to `native` to enable. The PR also enables new CI steps that test just the Rust parser, as well as steps that produce binary wheels for a variety of CPython versions and platforms.

Note: this PR aims to be roughly feature-equivalent to the main branch, so it doesn't include new 3.10 syntax features. That will be addressed as a follow-up PR.

The new parser is implemented in the `native/` directory, and is organized into two rust crates: `libcst_derive` contains some macros to facilitate various features of CST nodes, and `libcst` contains the `parser` itself (including the Python grammar), a `tokenizer` implementation by @bgw, and a very basic representation of CST `nodes`. Parsing is done by
1. **tokenizing** the input utf-8 string (bytes are not supported at the Rust layer, they are converted to utf-8 strings by the python wrapper)
2. running the **PEG parser** on the tokenized input, which also captures certain anchor tokens in the resulting syntax tree
3. using the anchor tokens to **inflate** the syntax tree into a proper CST

Co-authored-by: Benjamin Woodruff <github@benjam.info>
2021-12-21 18:14:39 +00:00
Steven Troxler
5e1e3fe970
The ufmt tool combines usort and black with a consistent wrapper, (#515)
which ensures we won't have inconsistent black-vs-isort errors
going forward. We can always format by running `ufmt format .`
at the root, and check with `ufmt check .` in our CI actions.
2021-08-25 20:39:29 -04:00
Tim Hatch
02fc4401bc
Support Named Unicode Characters and yield in f-strings (#424)
* Support named unicode characters in f-strings

This is the same as my pull request
https://github.com/davidhalter/parso/pull/160

* A small bugfix to what is allowed in f-string expressions

Thanks to https://github.com/davidhalter/parso/pull/159 for catching
that yield (as an expression, I suppose) is allowed on 3.6.
2020-11-30 12:42:13 +08:00
Tim Hatch
90df5a6a37
Allow generator expressions in f-strings (#419)
Fixes #388
2020-11-17 17:32:43 +00:00
Tim Hatch
31bae01ccb
Correct handling of walrus operator in function args (#417)
Previous behavior treated it as identical to equal, making a kwarg; it should
instead be a positional arg.  Includes several tests to make sure that
whitespace handling is correct.

Fixes #416
2020-11-12 21:14:34 -08:00
Jimmy Lai
7ca738bf39
Upgrade dev tools (Black/Flake8/isort) and read install requirements from requirements.txt (#380)
* Read install requirements from requirements.txt

* read extras_require from requirements-dev.txt

* add requirements-dev.txt to MANIFEST.in

* apply fixes for new version of Black and Flake8

* don't upgrade Pyre

* re-format
2020-08-31 10:44:55 -07:00
Germán Méndez Bravo
17bde3b3aa
Fix pyre syntax error in tokenizer stub (#360)
## Summary

The pyre stub for the tokenizer module had a syntax error.
Fixing it removes other pyre errors.

## Test Plan

```
pyre check
```

Co-authored-by: Germán Méndez Bravo <kronuz@fb.com>
2020-08-04 17:33:55 -07:00
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
8053cdbc6e [parsing 3.1] with multiple items 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
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
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
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
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