Skip to content
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

Implement a Python PEG parser in Rust #566

Merged
merged 208 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
208 commits
Select commit Hold shift + click to select a range
7d61ed2
[native] Add a rust implementation of whitespace_parser
bgw Jan 24, 2021
d24e6dd
[native] Add a native implementation of the tokenizer
bgw Mar 14, 2021
f0d3004
Basic FunctionDefinition parsing and codegen
zsol Mar 31, 2021
44e785a
add license headers
zsol Jun 25, 2021
f471daf
Convert WhitespaceState to not own absolute indent and move it to parser
zsol Jun 25, 2021
e26a9c3
remove python wrappers for now
zsol Jun 25, 2021
68516a6
expressions
zsol Jun 29, 2021
728d856
tracing
zsol Jun 29, 2021
275774d
nicer error messages
zsol Jun 29, 2021
1b2b8ea
bump peg version
zsol Jun 29, 2021
b32f953
prettier error messages
zsol Jun 29, 2021
3ed1b40
newline handling
zsol Jun 29, 2021
e198d01
blocks
zsol Jul 1, 2021
d195023
nicer error messages
zsol Jul 1, 2021
f83cf4f
remove unused dep
zsol Jul 2, 2021
f5fff7c
only show part of input in error msg
zsol Jul 2, 2021
222e89e
keep newlines when splitting by line
zsol Jul 2, 2021
f02c2bf
if statements
zsol Jul 2, 2021
4414c5f
parameters
zsol Jul 4, 2021
0c040dc
add func def fixture
zsol Jul 4, 2021
a568392
more whitespace to function def
zsol Jul 6, 2021
07812f1
tweak benchmarks
zsol Jul 6, 2021
dff70a6
improve codegen perf
zsol Jul 6, 2021
f83355b
use cpu cycles for benchmarks
zsol Jul 6, 2021
f1a363e
imports
zsol Jul 7, 2021
0180d33
add test fixture
zsol Jul 7, 2021
d4de127
add parentheses to imports
zsol Jul 7, 2021
7ecd5ae
eliminate warnings
zsol Jul 9, 2021
9c06f52
comparisons (note tests are failing because operator parsing is not i…
zsol Jul 9, 2021
016809d
operators
zsol Jul 13, 2021
017b3d5
module footer
zsol Jul 13, 2021
13884fa
sprinkle #[cached]
zsol Jul 13, 2021
de0c861
make sure keywords dont match names
zsol Jul 14, 2021
e293b3c
prettier roundtrip failures
zsol Jul 14, 2021
0c28628
fix attr_or_name order
zsol Jul 14, 2021
c22c825
add comments fixture
zsol Jul 14, 2021
e7855ff
add assign target grammar
zsol Jul 15, 2021
f02bdee
name rule returns Name
zsol Jul 15, 2021
7d032f9
assignment
zsol Jul 15, 2021
cf45134
tuples
zsol Jul 15, 2021
cf7c69b
add assignment fixtures
zsol Jul 16, 2021
020eaab
parentheses
zsol Jul 17, 2021
eef5556
clippy
zsol Jul 18, 2021
5d8cc59
fix module footer parsing
zsol Jul 21, 2021
a873e30
call expressions
zsol Jul 23, 2021
459669e
left-recursive call expressions
zsol Jul 23, 2021
67154ee
attributes!
zsol Jul 23, 2021
b71b511
split up into multiple crates
zsol Jul 24, 2021
e3de8d3
more comp ops
zsol Jul 27, 2021
5318e19
add comprehension nodes
zsol Jul 28, 2021
9da7587
generator expressions
zsol Jul 28, 2021
9a45768
fix warnings
zsol Jul 28, 2021
db94cdc
allow call expressions in target positions
zsol Jul 28, 2021
bc148f5
list comprehensions
zsol Jul 28, 2021
d76e8d1
set comprehensions
zsol Jul 28, 2021
6360bea
dict comprehensions
zsol Jul 28, 2021
a4a66ce
nodes for set/dict/list
zsol Jul 28, 2021
13881a4
list and set literals
zsol Jul 29, 2021
bb7a5dd
dict literals - this completes the atom subgrammar
zsol Jul 29, 2021
ac98c27
subscript
zsol Jul 29, 2021
1f895f8
add missing workspace config for cargo
zsol Jul 30, 2021
2bc2023
new clippy fixes
zsol Jul 30, 2021
e6b612c
tuple shenanigans
zsol Jul 30, 2021
680700b
add evil
zsol Jul 30, 2021
f74a4ba
fix left-recursive rules
zsol Jul 31, 2021
78597e1
starred elements on RHS of assign
zsol Jul 31, 2021
1051636
fix utf8 handling during whitespace parsing
zsol Jul 31, 2021
ecad6b7
lists in star_atom
zsol Aug 1, 2021
e8a0675
more caching
zsol Aug 1, 2021
f6336a4
ifexp
zsol Aug 1, 2021
f0b0d0f
fix arguments with no trailing comma
zsol Aug 1, 2021
c95eecc
lambdas
zsol Aug 1, 2021
44f0f4f
ann assign
zsol Aug 1, 2021
3d26a40
yield
zsol Aug 1, 2021
3decc7d
return statement
zsol Aug 2, 2021
6075910
assert statement
zsol Aug 2, 2021
cf8855b
raise statement
zsol Aug 2, 2021
5ed3034
global and nonlocal statements
zsol Aug 2, 2021
d5c19c5
for loops
zsol Aug 2, 2021
44a8084
while statement
zsol Aug 2, 2021
72a3e7e
async/await
zsol Aug 2, 2021
2febb8d
handle whitespace after last param
zsol Aug 2, 2021
cb4b49c
handle trailing whitespace in lambda params
zsol Aug 2, 2021
afe78a7
classes
zsol Aug 3, 2021
a04a607
concatenated strings
zsol Aug 3, 2021
0d23fa7
add string fixtures
zsol Aug 4, 2021
c47501c
fstrings
zsol Aug 4, 2021
ffc69bc
fix duplicate whitespace between trailing comma and rpar in ImportFrom
zsol Aug 4, 2021
b6ec2af
fix lookahead in target rules
zsol Aug 5, 2021
8c8c80a
try
zsol Aug 5, 2021
f6bf52a
aug assign
zsol Aug 5, 2021
1293ea7
add fixtures for try
zsol Aug 5, 2021
e3daedc
add with_parens for all expressions
zsol Aug 5, 2021
36a2b88
more yield weirdness
zsol Aug 5, 2021
61220ab
fixup leading whitespace parsing
zsol Aug 6, 2021
98df73e
fix decorators
zsol Aug 6, 2021
6d2de41
with statements
zsol Aug 6, 2021
0293158
fix indent parsing
zsol Aug 6, 2021
67b470f
dotted annotated assignments
zsol Aug 6, 2021
116cf50
allow files without statements
zsol Aug 6, 2021
3b41fbc
del statements
zsol Aug 6, 2021
0b6a819
allow no params for lambda
zsol Aug 6, 2021
ab444e3
add missing fixtures
zsol Aug 6, 2021
735d9c0
exit with 1 for parse errors
zsol Aug 8, 2021
3928e01
fix parsing with missing NL at EOF
zsol Aug 8, 2021
2967095
module header
zsol Aug 8, 2021
ae9b436
fix fstring spec parsing
zsol Aug 7, 2021
332cca5
fix ci
zsol Aug 14, 2021
3839b90
add rust CI
zsol Aug 14, 2021
adfef46
fix python CI
zsol Aug 14, 2021
2dcbfc2
add rustfmt and run cargo test
zsol Aug 14, 2021
ee78151
suppress f401
zsol Aug 14, 2021
25a81ee
tweak pyre exclude
zsol Aug 14, 2021
344fa7d
fix build.yml syntax
zsol Aug 14, 2021
01f11c8
i know how to use #noqa :P
zsol Aug 14, 2021
9fe9225
tweak pyre exclude regex
zsol Aug 14, 2021
a9cf52c
fix isort
zsol Aug 14, 2021
0e3ba0c
fix black & isort
zsol Aug 14, 2021
1126908
fix argument parsing for `foo(a=a, *b)`
zsol Aug 14, 2021
52f8d58
display details of tokenizer error
zsol Aug 14, 2021
a59fc2c
swallow UTF-8 BOM from input
zsol Aug 14, 2021
f1b5121
Track ownership of newlines
zsol Aug 17, 2021
896b74a
fix double whitespace for empty dict/set/list literals
zsol Aug 26, 2021
e240f6d
fix extra whitespace for no-arg return
zsol Aug 26, 2021
8175451
semicolons
zsol Aug 26, 2021
6f9aafd
Introduce inflate as a separate step post-parse
zsol Aug 28, 2021
139bf88
merge all crates back into one
zsol Aug 28, 2021
58c6772
remove duplicate structs
zsol Aug 28, 2021
2be0522
add derive macro for Inflate
zsol Aug 29, 2021
2225631
add roundtrip script
zsol Aug 29, 2021
62fff69
move inflate implementations next to nodes
zsol Aug 29, 2021
399af5a
inflate for functiondef and decorator
zsol Aug 29, 2021
14cc28b
Inflate for If and Else
zsol Aug 29, 2021
d1a502b
Inflate for CompoundStatements
zsol Aug 29, 2021
7aa7ad1
remove debug statement
zsol Aug 29, 2021
00feef0
remove struct enum variants from SmallStatement
zsol Aug 30, 2021
075d1c6
remove struct enum variants from Expression
zsol Aug 30, 2021
5c7d6c0
use automatic deriving for Codegen and ParenthesizedNode
zsol Aug 30, 2021
41085bd
Inflate for Expressions
zsol Sep 1, 2021
cf78ce8
construct lpar outside of class def
zsol Sep 1, 2021
011828f
run rust CI tests in release mode temporarily
zsol Sep 1, 2021
db48ff3
fix whitespace around slice parenthesis
zsol Sep 1, 2021
29ddba9
add fixture
zsol Sep 1, 2021
51f190a
share token and whitespace between CST nodes
zsol Sep 3, 2021
aecf429
cargo fix
zsol Sep 3, 2021
29b1042
elide redundant lifetimes
zsol Sep 3, 2021
b58ce62
remove TODOs related to whitespace adjustments
zsol Sep 3, 2021
def50fc
remove janky parse_empty_lines_from_end function
zsol Sep 3, 2021
49249a2
no need to run cargo test with --release anymore
zsol Sep 3, 2021
34f9b5d
clean up unnecessary line ownership tracker code
zsol Sep 3, 2021
78794d4
Token does not need a RefCell wrapper
zsol Sep 3, 2021
cec6afe
add tricky comments cases
zsol Sep 3, 2021
b303ce1
concatenate all fixtures in benchmark to extend coverage
zsol Sep 3, 2021
894554b
remove grammar dependency on whitespace config
zsol Sep 4, 2021
c1d73da
add separate benchmarks for tokenize/parse/inflate/codegen
zsol Sep 4, 2021
0d8062f
expose native API via Python
zsol Sep 6, 2021
350449a
fix invalid test case
zsol Sep 6, 2021
bc9c2fd
revert accidental debugging
zsol Sep 6, 2021
cd75963
handle optional values with defaults during IntoPy
zsol Sep 6, 2021
5ae79cd
special case IntoPy for DictElement
zsol Sep 6, 2021
7d55318
expose native libs at libcst.native and add env var to turn it on
zsol Oct 11, 2021
06cca35
IndentedBlock.indent should be None when it matches default indent
zsol Oct 11, 2021
09d9543
set extra attributes on Module
zsol Oct 12, 2021
57b3ccf
parse floats and imaginaries
zsol Oct 13, 2021
2e46eab
Add proper expression and statement input rules
zsol Oct 13, 2021
7abcad6
add IntoPy implementation for enums with named fields
zsol Oct 13, 2021
2e27f45
allow missing f-string spec
zsol Oct 14, 2021
cc753df
support raw f-strings
zsol Oct 14, 2021
c13f318
support more expressions in f-strings
zsol Oct 14, 2021
bb65955
allow yield expression in f-strings (?!?!?!)
zsol Oct 14, 2021
3607030
disable tests asserting parse error for certain python versions when …
zsol Oct 14, 2021
97db278
fix IntoPy impl for DictElement
zsol Oct 15, 2021
1bf4536
rename DoubleStarredElement -> StarredDictElement to match pure py im…
zsol Oct 15, 2021
9885372
skip version-specific parse error test
zsol Oct 15, 2021
680ef58
fix FunctionDef tests
zsol Oct 15, 2021
9dd903a
fix list and set tests
zsol Oct 15, 2021
7e96f87
convert UnaryOp variants into named fields
zsol Oct 15, 2021
9690cee
fix parsing of single simplestatements with trailing semicolon
zsol Oct 16, 2021
8cdd027
parse files with trailing comment without newline
zsol Oct 16, 2021
ae8cef4
fix IntoPy for ImportFrom without a module attribute
zsol Oct 16, 2021
5f59733
factor out separated meta-rule
zsol Oct 16, 2021
10091a0
fix invalid testcases
zsol Oct 16, 2021
b68215a
only set whitespace_after_raise if theres an exception
zsol Oct 16, 2021
7a5da79
whitespace_after_return is never None
zsol Oct 16, 2021
69cf4f7
preserve left paren order in expressions
zsol Oct 16, 2021
465b1c0
trailing comma doesnt own whitespace_after for tuple/list/dict/set
zsol Oct 17, 2021
0ed4685
implement walrus
zsol Oct 17, 2021
2c6b7dc
fix parsing of triple dots in import_from
zsol Oct 17, 2021
ed1c373
fix module header processing
zsol Oct 17, 2021
88b7b27
disable singleton newline test in native mode
zsol Oct 17, 2021
b93b572
detect default_newline
zsol Oct 17, 2021
9270360
fix simple test case
zsol Oct 17, 2021
9d1a90b
parse_expression should accept tuples
zsol Oct 17, 2021
ba5d376
raise ParserSyntaxError in python land
zsol Oct 18, 2021
177b8dd
populate syntax error details where available
zsol Oct 18, 2021
418ff39
add check for pos arg after kw arg in class def
zsol Nov 2, 2021
63c4f71
skip version tests in native mode
zsol Dec 8, 2021
a3dfea6
add support for parsing from bytes
zsol Dec 8, 2021
785af81
thread through encoding field to Module
zsol Dec 8, 2021
6557c2c
fix test to coerce call args to tuple
zsol Dec 8, 2021
6925202
update codegen and formatting
zsol Dec 16, 2021
27cd771
run unittests with rust too
zsol Dec 8, 2021
e430bbd
use cibw to build wheels
zsol Dec 16, 2021
e363058
fix codemod cli test in native/3.6 mode
zsol Dec 17, 2021
30efa4e
fix rust unittests on macos
zsol Dec 17, 2021
bfa285f
revert accidental test change
zsol Dec 20, 2021
b188f42
address review comments & reorder grammar rules to match CPython
zsol Dec 21, 2021
11cd13b
silence lints
zsol Dec 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]

[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
root = true

[*.{py,pyi,toml,md}]
[*.{py,pyi,rs,toml,md}]
charset = "utf-8"
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 88

[*.rs]
# https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/guide.md
max_line_length = 100
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ exclude =
.pyre,
__pycache__,
.tox,
native,

max-complexity = 12

3 changes: 3 additions & 0 deletions .github/workflows/.pyre_configuration.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"exclude": [
".*\/native\/.*"
],
"source_directories": [
"."
],
Expand Down
95 changes: 89 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.6, 3.7, 3.8, 3.9]
parser: [pure, native]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
Expand All @@ -48,8 +49,14 @@ jobs:
- name: Validate Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: exit 1
- if: ${{ matrix.parser == 'native' }}
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- run: >-
echo LIBCST_PARSER_TYPE=${{ matrix.parser }} >> $GITHUB_ENV
- name: Run Tests
run: python -m unittest
run: python setup.py test

# Run linters
lint:
Expand Down Expand Up @@ -166,10 +173,37 @@ jobs:

# Build python package
build:
name: Build wheels on ${{ matrix.os }}/${{ matrix.vers }}
needs: setup
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- vers: i686
os: ubuntu-20.04
# aarch64 seems to be stuck
# - vers: aarch64
# os: ubuntu-20.04
- vers: auto64
os: ubuntu-20.04
- vers: arm64
os: macos-10.15
- vers: auto64
os: macos-10.15
- vers: auto64
os: windows-2019
env:
SCCACHE_VERSION: 0.2.13
CIBW_BEFORE_ALL_LINUX: "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y"
CIBW_BEFORE_ALL_MACOS: "rustup target add aarch64-apple-darwin x86_64-apple-darwin"
CIBW_BEFORE_ALL_WINDOWS: "rustup target add x86_64-pc-windows-msvc i686-pc-windows-msvc"
CIBW_ENVIRONMENT: 'PATH="$PATH:$HOME/.cargo/bin"'
CIBW_SKIP: "cp27-* cp34-* cp35-* pp* *-win32 *-win_arm64 *-musllinux_*"
CIBW_ARCHS: ${{ matrix.vers }}
CIBW_BUILD_VERBOSITY: 1
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9
Expand All @@ -185,17 +219,66 @@ jobs:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: >-
echo LIBCST_NO_LOCAL_SCHEME=1 >> $GITHUB_ENV
- name: Build a binary wheel and a source tarball
- name: Build wheels
uses: pypa/cibuildwheel@v2.3.1
- uses: actions/upload-artifact@v2
with:
path: wheelhouse/*.whl
- name: Build a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
--outdir wheelhouse/
- if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
packages_dir: wheelhouse/

# Test rust parts
native:
name: Rust unit tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- uses: actions/setup-python@v2
with:
python-version: 3.9
- name: test
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=native/Cargo.toml
- name: clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --manifest-path=native/Cargo.toml --all-features

rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --manifest-path=native/Cargo.toml -- --check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ libcst/_version.py
.hypothesis/
.pyre_configuration
.python-version
target/
6 changes: 4 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
All contributions towards LibCST are MIT licensed.

Some Python files have been taken from the standard library and are therefore
Some Python files have been derived from the standard library and are therefore
PSF licensed. Modifications on these files are dual licensed (both MIT and
PSF). These files are:

- libcst/_parser/base_parser.py
- libcst/_parser/parso/utils.py
- libcst/_parser/parso/pgen2/generator.py
- libcst/_parser/parso/pgen2/grammar_parser.py
- libcst/_parser/parso/python/token.py
- libcst/_parser/parso/python/py_token.py
- libcst/_parser/parso/python/tokenize.py
- libcst/_parser/parso/tests/test_fstring.py
- libcst/_parser/parso/tests/test_tokenize.py
- libcst/_parser/parso/tests/test_utils.py
- libcst_native/src/tokenize/core/mod.rs
- libcst_native/src/tokenize/core/string_types.rs

Some Python files have been taken from dataclasses and are therefore Apache
licensed. Modifications on these files are licensed under Apache 2.0 license.
Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
include README.rst LICENSE CODE_OF_CONDUCT.md CONTRIBUTING.md requirements.txt requirements-dev.txt docs/source/*.rst libcst/py.typed

include native/Cargo.toml
recursive-include native *
3 changes: 3 additions & 0 deletions libcst/_nodes/tests/test_atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import libcst as cst
from libcst import parse_expression
from libcst._nodes.tests.base import CSTNodeTest, parse_expression_as
from libcst._parser.entrypoints import is_native
from libcst.metadata import CodeRange
from libcst.testing.utils import data_provider

Expand Down Expand Up @@ -1120,6 +1121,8 @@ def test_invalid(self, **kwargs: Any) -> None:
)
)
def test_versions(self, **kwargs: Any) -> None:
if is_native() and not kwargs.get("expect_success", True):
self.skipTest("parse errors are disabled for native parser")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a plan for making them work? This is an important part of the API.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's possible to make it work, but my priority is to get 3.10 working first. The old parser won't be removed until this feature is supported by the new one.

self.assert_parses(**kwargs)


Expand Down
3 changes: 3 additions & 0 deletions libcst/_nodes/tests/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import libcst as cst
from libcst import parse_expression
from libcst._nodes.tests.base import CSTNodeTest, parse_expression_as
from libcst._parser.entrypoints import is_native
from libcst.metadata import CodeRange
from libcst.testing.utils import data_provider

Expand Down Expand Up @@ -187,4 +188,6 @@ def test_invalid(self, **kwargs: Any) -> None:
)
)
def test_versions(self, **kwargs: Any) -> None:
if is_native() and not kwargs.get("expect_success", True):
self.skipTest("parse errors are disabled for native parser")
self.assert_parses(**kwargs)
3 changes: 3 additions & 0 deletions libcst/_nodes/tests/test_funcdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import libcst as cst
from libcst import parse_statement
from libcst._nodes.tests.base import CSTNodeTest, DummyIndentedBlock, parse_statement_as
from libcst._parser.entrypoints import is_native
from libcst.metadata import CodeRange
from libcst.testing.utils import data_provider

Expand Down Expand Up @@ -2041,4 +2042,6 @@ def test_valid_38(self, node: cst.CSTNode, code: str) -> None:
)
)
def test_versions(self, **kwargs: Any) -> None:
if is_native() and not kwargs.get("expect_success", True):
self.skipTest("parse errors are disabled for native parser")
self.assert_parses(**kwargs)
4 changes: 3 additions & 1 deletion libcst/_nodes/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,10 @@ class ImportFromParseTest(CSTNodeTest):
),
cst.ImportAlias(cst.Name("baz"), comma=cst.Comma()),
),
lpar=cst.LeftParen(),
rpar=cst.RightParen(),
),
"code": "from foo import bar, baz,",
"code": "from foo import (bar, baz,)",
},
# Star import statement
{
Expand Down
3 changes: 3 additions & 0 deletions libcst/_nodes/tests/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import libcst as cst
from libcst import parse_expression, parse_statement
from libcst._nodes.tests.base import CSTNodeTest, parse_expression_as
from libcst._parser.entrypoints import is_native
from libcst.metadata import CodeRange
from libcst.testing.utils import data_provider

Expand Down Expand Up @@ -126,4 +127,6 @@ def test_invalid(
)
)
def test_versions(self, **kwargs: Any) -> None:
if is_native() and not kwargs.get("expect_success", True):
self.skipTest("parse errors are disabled for native parser")
self.assert_parses(**kwargs)
3 changes: 3 additions & 0 deletions libcst/_nodes/tests/test_matrix_multiply.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
parse_expression_as,
parse_statement_as,
)
from libcst._parser.entrypoints import is_native
from libcst.testing.utils import data_provider


Expand Down Expand Up @@ -69,4 +70,6 @@ def test_valid(self, **kwargs: Any) -> None:
)
)
def test_versions(self, **kwargs: Any) -> None:
if is_native() and not kwargs.get("expect_success", True):
self.skipTest("parse errors are disabled for native parser")
self.assert_parses(**kwargs)
8 changes: 7 additions & 1 deletion libcst/_nodes/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import libcst as cst
from libcst import parse_module, parse_statement
from libcst._nodes.tests.base import CSTNodeTest
from libcst._parser.entrypoints import is_native
from libcst.metadata import CodeRange, MetadataWrapper, PositionProvider
from libcst.testing.utils import data_provider

Expand Down Expand Up @@ -83,6 +84,7 @@ def test_code_for_node(
"empty_program_with_newline": {
"code": "\n",
"expected": cst.Module([], has_trailing_newline=True),
"enabled_for_native": False,
},
"empty_program_with_comments": {
"code": "# some comment\n",
Expand Down Expand Up @@ -112,7 +114,11 @@ def test_code_for_node(
},
}
)
def test_parser(self, *, code: str, expected: cst.Module) -> None:
def test_parser(
self, *, code: str, expected: cst.Module, enabled_for_native: bool = True
) -> None:
if is_native() and not enabled_for_native:
self.skipTest("Disabled for native parser")
self.assertEqual(parse_module(code), expected)

@data_provider(
Expand Down
3 changes: 3 additions & 0 deletions libcst/_nodes/tests/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import libcst as cst
from libcst import parse_expression
from libcst._nodes.tests.base import CSTNodeTest, parse_expression_as
from libcst._parser.entrypoints import is_native
from libcst.testing.utils import data_provider


Expand Down Expand Up @@ -133,4 +134,6 @@ def test_invalid(
)
)
def test_versions(self, **kwargs: Any) -> None:
if is_native() and not kwargs.get("expect_success", True):
self.skipTest("parse errors are disabled for native parser")
self.assert_parses(**kwargs)
Loading