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

Format ExprName #4803

Merged
merged 1 commit into from
Jun 3, 2023
Merged

Format ExprName #4803

merged 1 commit into from
Jun 3, 2023

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jun 2, 2023

Summary

Implements formatting of ExprName.

We, unfortunately, don't have the Identifier range. Luckily, we get away by simply using the Name range because it only encloses the Identifier.

    <location:@L> <name:Identifier> <end_location:@R> => ast::Expr::Name(
        ast::ExprName { id: name, ctx: ast::ExprContext::Load, range: (location..end_location).into() }
    ),

We may need to inspect the source code in other places to get the Identifier's range, or decide not to bother and use dynamic_text if the syntax element is rarely used (e.g. nonlocal).

Test Plan

I added a new test asserting my assumption that the name and identifier ranges are identical.

There are no snapshot changes because the new implementation slices the same text as the verbatim_range implementation.

@MichaReiser
Copy link
Member Author

MichaReiser commented Jun 2, 2023

@MichaReiser MichaReiser added internal An internal refactor or improvement formatter Related to the formatter labels Jun 2, 2023
@MichaReiser MichaReiser linked an issue Jun 2, 2023 that may be closed by this pull request
@github-actions
Copy link
Contributor

github-actions bot commented Jun 2, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
linter/all-rules/large/dataset.py          1.00     15.0±0.03ms     2.7 MB/sec    1.00     14.9±0.03ms     2.7 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.6±0.01ms     4.6 MB/sec    1.00      3.6±0.01ms     4.6 MB/sec
linter/all-rules/numpy/globals.py          1.01    374.8±1.30µs     7.9 MB/sec    1.00    372.0±1.61µs     7.9 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.3±0.01ms     4.1 MB/sec    1.00      6.2±0.01ms     4.1 MB/sec
linter/default-rules/large/dataset.py      1.00      7.5±0.01ms     5.5 MB/sec    1.00      7.4±0.01ms     5.5 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1582.2±2.42µs    10.5 MB/sec    1.00   1583.3±6.09µs    10.5 MB/sec
linter/default-rules/numpy/globals.py      1.00    172.4±0.22µs    17.1 MB/sec    1.00    173.1±0.81µs    17.0 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.4±0.00ms     7.6 MB/sec    1.00      3.4±0.01ms     7.6 MB/sec
parser/large/dataset.py                    1.00      5.7±0.00ms     7.1 MB/sec    1.00      5.7±0.00ms     7.1 MB/sec
parser/numpy/ctypeslib.py                  1.01   1139.6±1.29µs    14.6 MB/sec    1.00   1125.9±1.43µs    14.8 MB/sec
parser/numpy/globals.py                    1.00    115.6±0.55µs    25.5 MB/sec    1.01    116.3±1.52µs    25.4 MB/sec
parser/pydantic/types.py                   1.00      2.5±0.00ms    10.3 MB/sec    1.00      2.5±0.01ms    10.4 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
linter/all-rules/large/dataset.py          1.00     16.7±0.23ms     2.4 MB/sec    1.00     16.7±0.23ms     2.4 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      4.2±0.06ms     3.9 MB/sec    1.01      4.2±0.16ms     3.9 MB/sec
linter/all-rules/numpy/globals.py          1.00    499.2±5.62µs     5.9 MB/sec    1.01    503.0±7.61µs     5.9 MB/sec
linter/all-rules/pydantic/types.py         1.00      7.0±0.08ms     3.6 MB/sec    1.00      7.0±0.08ms     3.6 MB/sec
linter/default-rules/large/dataset.py      1.00      8.2±0.08ms     5.0 MB/sec    1.00      8.2±0.07ms     5.0 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1748.7±23.26µs     9.5 MB/sec    1.00  1747.5±14.54µs     9.5 MB/sec
linter/default-rules/numpy/globals.py      1.00    201.9±2.91µs    14.6 MB/sec    1.02    205.2±5.53µs    14.4 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.7±0.03ms     6.9 MB/sec    1.01      3.7±0.04ms     6.8 MB/sec
parser/large/dataset.py                    1.00      6.3±0.04ms     6.4 MB/sec    1.01      6.4±0.05ms     6.3 MB/sec
parser/numpy/ctypeslib.py                  1.00  1194.9±15.47µs    13.9 MB/sec    1.02  1215.7±16.27µs    13.7 MB/sec
parser/numpy/globals.py                    1.00    122.8±1.71µs    24.0 MB/sec    1.02    124.7±2.72µs    23.7 MB/sec
parser/pydantic/types.py                   1.00      2.7±0.03ms     9.4 MB/sec    1.01      2.7±0.03ms     9.3 MB/sec

Copy link
Member

@konstin konstin left a comment

Choose a reason for hiding this comment

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

Also formats StmtExpr and changes the snapshots, but both look good

@MichaReiser MichaReiser merged commit 2c41c54 into main Jun 3, 2023
@MichaReiser MichaReiser deleted the format-expr-name branch June 3, 2023 14:06
konstin pushed a commit that referenced this pull request Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatter: Name
3 participants