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 visitation of type aliases and parameters #5927

Merged
merged 14 commits into from
Jul 25, 2023
Merged

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Jul 20, 2023

Summary

Part of #5062
Requires astral-sh/RustPython-Parser#32

Adds visitation of type alias statements and type parameters in class and function definitions.

Duplicates tests for PreorderVisitor into Visitor with new snapshots. Testing required node implementations for the TypeParam enum, which is a chunk of the diff and the reason we need Ranged implementations in astral-sh/RustPython-Parser#32.

Test Plan

Adds unit tests with snapshots.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 20, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00     10.3±0.61ms     4.0 MB/sec    1.06     10.9±0.15ms     3.7 MB/sec
formatter/numpy/ctypeslib.py               1.03      2.2±0.03ms     7.6 MB/sec    1.00      2.1±0.05ms     7.8 MB/sec
formatter/numpy/globals.py                 1.00    236.4±6.55µs    12.5 MB/sec    1.08   254.7±16.18µs    11.6 MB/sec
formatter/pydantic/types.py                1.00      4.5±0.15ms     5.6 MB/sec    1.00      4.5±0.13ms     5.6 MB/sec
linter/all-rules/large/dataset.py          1.00     14.6±0.43ms     2.8 MB/sec    1.01     14.8±0.21ms     2.7 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.8±0.07ms     4.4 MB/sec    1.00      3.8±0.04ms     4.4 MB/sec
linter/all-rules/numpy/globals.py          1.00    493.3±6.55µs     6.0 MB/sec    1.00    492.4±9.35µs     6.0 MB/sec
linter/all-rules/pydantic/types.py         1.04      6.8±0.10ms     3.8 MB/sec    1.00      6.5±0.24ms     3.9 MB/sec
linter/default-rules/large/dataset.py      1.00      7.6±0.12ms     5.3 MB/sec    1.00      7.6±0.18ms     5.4 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.03  1652.6±17.93µs    10.1 MB/sec    1.00  1609.1±42.32µs    10.3 MB/sec
linter/default-rules/numpy/globals.py      1.00    173.8±7.02µs    17.0 MB/sec    1.01    175.3±6.08µs    16.8 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.4±0.13ms     7.6 MB/sec    1.02      3.4±0.12ms     7.5 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00     10.8±0.05ms     3.8 MB/sec    1.00     10.8±0.08ms     3.8 MB/sec
formatter/numpy/ctypeslib.py               1.01      2.1±0.02ms     7.8 MB/sec    1.00      2.1±0.02ms     7.9 MB/sec
formatter/numpy/globals.py                 1.00    229.7±2.97µs    12.8 MB/sec    1.00    229.2±3.09µs    12.9 MB/sec
formatter/pydantic/types.py                1.00      4.7±0.03ms     5.4 MB/sec    1.00      4.7±0.04ms     5.4 MB/sec
linter/all-rules/large/dataset.py          1.00     15.2±0.13ms     2.7 MB/sec    1.01     15.4±0.11ms     2.6 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      4.0±0.03ms     4.1 MB/sec    1.01      4.1±0.04ms     4.1 MB/sec
linter/all-rules/numpy/globals.py          1.00    409.1±6.98µs     7.2 MB/sec    1.01    413.8±6.73µs     7.1 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.9±0.06ms     3.7 MB/sec    1.03      7.1±0.09ms     3.6 MB/sec
linter/default-rules/large/dataset.py      1.00      8.0±0.05ms     5.1 MB/sec    1.01      8.1±0.05ms     5.0 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1616.8±12.96µs    10.3 MB/sec    1.02  1641.9±14.93µs    10.1 MB/sec
linter/default-rules/numpy/globals.py      1.00    173.7±1.62µs    17.0 MB/sec    1.00    174.5±2.06µs    16.9 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.6±0.08ms     7.0 MB/sec    1.01      3.7±0.04ms     7.0 MB/sec

@zanieb zanieb marked this pull request as draft July 20, 2023 17:57
Cargo.toml Outdated
Comment on lines 55 to 59
ruff_text_size = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "86f4dc8869bbab5786a39cc6d1e6083c12d65e6e" }
rustpython-ast = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "86f4dc8869bbab5786a39cc6d1e6083c12d65e6e" , default-features = false, features = ["num-bigint"]}
rustpython-format = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "86f4dc8869bbab5786a39cc6d1e6083c12d65e6e", default-features = false, features = ["num-bigint"] }
rustpython-literal = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "86f4dc8869bbab5786a39cc6d1e6083c12d65e6e", default-features = false }
rustpython-parser = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "86f4dc8869bbab5786a39cc6d1e6083c12d65e6e" , default-features = false, features = ["full-lexer", "num-bigint"] }
Copy link
Member Author

Choose a reason for hiding this comment

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

This pin is temporary and will need to be amended on merge of astral-sh/RustPython-Parser#32

@@ -0,0 +1,13 @@
---
source: crates/ruff_python_ast/src/visitor.rs
Copy link
Member Author

@zanieb zanieb Jul 20, 2023

Choose a reason for hiding this comment

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

relevant test

@@ -0,0 +1,14 @@
---
source: crates/ruff_python_ast/src/visitor.rs
Copy link
Member Author

Choose a reason for hiding this comment

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

relevant test

@@ -0,0 +1,12 @@
---
source: crates/ruff_python_ast/src/visitor.rs
Copy link
Member Author

Choose a reason for hiding this comment

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

Most of these snapshots are new coverage of previous behavior with tests duplicated from the pre-order visitor.

@@ -0,0 +1,15 @@
---
source: crates/ruff_python_ast/src/visitor.rs
Copy link
Member Author

Choose a reason for hiding this comment

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

relevant test

@zanieb zanieb requested a review from charliermarsh July 20, 2023 18:17
charliermarsh pushed a commit to astral-sh/RustPython-Parser that referenced this pull request Jul 21, 2023
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

LGTM.

Can you search for all Visitor (preorder or normal) implementations and add the overrides for visit_type_params for visitors that must visit all nodes or do you plan to do this as separate PRS?

For example, it's important for the correctness of CommentsVisitor to override every node visiting function:

impl<'ast> PreorderVisitor<'ast> for CommentsVisitor<'ast> {

crates/ruff_python_ast/src/visitor.rs Outdated Show resolved Hide resolved
crates/ruff_python_ast/src/visitor.rs Show resolved Hide resolved
crates/ruff_python_ast/src/visitor.rs Show resolved Hide resolved
@zanieb zanieb force-pushed the zanie/695-visitor branch from 903a3a6 to e9cac63 Compare July 21, 2023 14:31
@zanieb
Copy link
Member Author

zanieb commented Jul 24, 2023

Can you search for all Visitor (preorder or normal) implementations and add the overrides for visit_type_params for visitors that must visit all nodes or do you plan to do this as separate PRS?

I'll do this here!

@zanieb zanieb force-pushed the zanie/695-visitor branch from e9cac63 to f560538 Compare July 24, 2023 20:26
@zanieb zanieb marked this pull request as ready for review July 24, 2023 20:29
@zanieb zanieb force-pushed the zanie/695-visitor branch from f560538 to c8f962a Compare July 25, 2023 15:45
@zanieb zanieb enabled auto-merge (squash) July 25, 2023 17:02
@zanieb zanieb merged commit 389fe13 into main Jul 25, 2023
@zanieb zanieb deleted the zanie/695-visitor branch July 25, 2023 17:11
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.

3 participants