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

Add tests for new python syntax #219

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

vors
Copy link

@vors vors commented Feb 17, 2024

Hello!

Here are tests that are legal python syntax (i.e. https://github.com/astral-sh/ruff parses it fine) but they are currently failing

thread 'extract_py_imports::tests::test_syntax_constructs' panicked at python_extractor/src/extract_py_imports.rs:162:68:
called `Result::unwrap()` on an `Err` value: invalid syntax. Got unexpected token '[' at line 7 column 30

I'm not sure that currently used parser is a good long-term choice to avoid that kind of problems.
Maybe we can switch to ruff parser altogether?

@eed3si9n
Copy link
Contributor

I think we use RustPython's parser, but the dependency is pinned to this commit - RustPython/RustPython@b9ed63e, which is 1409 commits behind RustPython/RustPython@b9ed63e...main.

@johnynek
Copy link
Collaborator

it looks like ruff doesn't seem to have an external parser dependency:

https://github.com/astral-sh/ruff/blob/main/crates/ruff_python_parser/Cargo.toml

I wonder if we can depend on their parser since I think that is fairly well tested across a bunch of code bases.

@vors
Copy link
Author

vors commented Feb 19, 2024

Another alternative would be to depend on the native CPython ast parser and dump it into json with something like https://pypi.org/project/ast2json/ then parse import in rust or perhaps just do this whole thing in python, but that would mean starting brining dependencies outside of rust ecosystem which is big design decision.

@vors
Copy link
Author

vors commented Feb 21, 2024

FWIW I found more constructs that don't work, I think it was mostly around the new match syntax.

value = 1
args = [int, float]
# this is a legal-in-runtime construction
def perform_cast(value, Union[*args])
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is legal?

@johnynek
Copy link
Collaborator

I merged main to pickup: #237

That should fix match issues, but your test surprises me that it is legal syntax.

@vors
Copy link
Author

vors commented Mar 21, 2024

Thank you, yes the [*foo] is legal syntax but pyright for example also has troubles with it at the moment. Ruff doesn't (and python 3.11.8 doesn't)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants