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 DictComp expression #5771

Merged
merged 3 commits into from
Jul 15, 2023
Merged

Conversation

cnpryer
Copy link
Contributor

@cnpryer cnpryer commented Jul 15, 2023

Summary

Format DictComp like ListComp from #5600. It's not 100%, but I figured maybe it's worth starting to explore.

Test Plan

Added ruff fixture based on ListComp's.

Comment on lines +339 to +342
+ for (
+ k,
+ v,
+ ) in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note the generators formatting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

You mean the parentheses around the tuple and that it expands over multiple lines? We probably need to use the StripInsideForLoop layout here as well (unrelated to your PR)

#5779

@github-actions
Copy link
Contributor

github-actions bot commented Jul 15, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      9.3±0.02ms     4.4 MB/sec    1.01      9.4±0.03ms     4.3 MB/sec
formatter/numpy/ctypeslib.py               1.00   1857.4±2.27µs     9.0 MB/sec    1.01   1868.2±3.25µs     8.9 MB/sec
formatter/numpy/globals.py                 1.00    207.6±1.00µs    14.2 MB/sec    1.01    209.9±0.30µs    14.1 MB/sec
formatter/pydantic/types.py                1.00      4.1±0.01ms     6.3 MB/sec    1.00      4.1±0.01ms     6.3 MB/sec
linter/all-rules/large/dataset.py          1.00     13.6±0.14ms     3.0 MB/sec    1.00     13.7±0.08ms     3.0 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.4±0.01ms     4.9 MB/sec    1.01      3.4±0.01ms     4.9 MB/sec
linter/all-rules/numpy/globals.py          1.00    449.6±0.86µs     6.6 MB/sec    1.00    451.0±1.63µs     6.5 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.1±0.07ms     4.2 MB/sec    1.00      6.1±0.04ms     4.2 MB/sec
linter/default-rules/large/dataset.py      1.00      6.7±0.07ms     6.1 MB/sec    1.01      6.8±0.02ms     6.0 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1467.1±2.43µs    11.4 MB/sec    1.01   1486.3±4.60µs    11.2 MB/sec
linter/default-rules/numpy/globals.py      1.00    166.4±0.91µs    17.7 MB/sec    1.02    169.0±0.22µs    17.5 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.0±0.01ms     8.5 MB/sec    1.02      3.1±0.01ms     8.3 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.01     11.7±0.45ms     3.5 MB/sec    1.00     11.5±0.55ms     3.5 MB/sec
formatter/numpy/ctypeslib.py               1.00      2.2±0.15ms     7.7 MB/sec    1.04      2.3±0.09ms     7.4 MB/sec
formatter/numpy/globals.py                 1.00    240.6±4.57µs    12.3 MB/sec    1.02    246.3±6.45µs    12.0 MB/sec
formatter/pydantic/types.py                1.00      4.6±0.06ms     5.5 MB/sec    1.01      4.7±0.05ms     5.5 MB/sec
linter/all-rules/large/dataset.py          1.03     16.3±0.65ms     2.5 MB/sec    1.00     15.8±0.45ms     2.6 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.05      4.3±0.21ms     3.8 MB/sec    1.00      4.1±0.05ms     4.0 MB/sec
linter/all-rules/numpy/globals.py          1.04  551.2±104.81µs     5.4 MB/sec    1.00   530.2±25.05µs     5.6 MB/sec
linter/all-rules/pydantic/types.py         1.00      7.3±0.28ms     3.5 MB/sec    1.02      7.5±0.30ms     3.4 MB/sec
linter/default-rules/large/dataset.py      1.00      8.2±0.32ms     4.9 MB/sec    1.00      8.2±0.27ms     5.0 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1744.6±70.40µs     9.5 MB/sec    1.01  1767.3±52.69µs     9.4 MB/sec
linter/default-rules/numpy/globals.py      1.00    202.1±4.98µs    14.6 MB/sec    1.01    204.9±8.17µs    14.4 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.8±0.13ms     6.7 MB/sec    1.00      3.8±0.14ms     6.8 MB/sec

@cnpryer cnpryer changed the title Format ExprDictComp Format DictComp expression Jul 15, 2023
@MichaReiser MichaReiser linked an issue Jul 15, 2023 that may be closed by this pull request
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.

Nice! Thank you.

Comment on lines +339 to +342
+ for (
+ k,
+ v,
+ ) in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension
Copy link
Member

Choose a reason for hiding this comment

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

You mean the parentheses around the tuple and that it expands over multiple lines? We probably need to use the StripInsideForLoop layout here as well (unrelated to your PR)

#5779

@MichaReiser MichaReiser merged commit fa4855e into astral-sh:main Jul 15, 2023
@cnpryer cnpryer deleted the expr-dict-comp branch July 15, 2023 16:41
evanrittenhouse pushed a commit to evanrittenhouse/ruff that referenced this pull request Jul 19, 2023
## Summary

Format `DictComp` like `ListComp` from astral-sh#5600. It's not 100%, but I
figured maybe it's worth starting to explore.

## Test Plan

Added ruff fixture based on `ListComp`'s.
konstin pushed a commit that referenced this pull request Jul 19, 2023
## Summary

Format `DictComp` like `ListComp` from #5600. It's not 100%, but I
figured maybe it's worth starting to explore.

## Test Plan

Added ruff fixture based on `ListComp`'s.
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.

Formatter: DictComp (depends on ListComp)
2 participants