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

Fix formatting of chained boolean operations #6394

Merged
merged 13 commits into from
Aug 7, 2023
Merged

Fix formatting of chained boolean operations #6394

merged 13 commits into from
Aug 7, 2023

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Aug 7, 2023

Closes #6068

These commits are kind of a mess as I did some stumbling around here.

Unrolls formatting of chained boolean operations to prevent nested grouping which gives us Black-compatible formatting where each boolean operation is on a new line.

@zanieb zanieb marked this pull request as draft August 7, 2023 15:49
Comment on lines 151 to 165
# Regression test for https://github.com/astral-sh/ruff/issues/6068
if not (
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
or numpy
and isinstance(ccccccccccc, dddddd)
):
pass

if not (
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
and numpy
or isinstance(ccccccccccc, dddddd)
):
pass
```
Copy link
Member Author

Choose a reason for hiding this comment

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

Yay!

@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2023

PR Check Results

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.01      8.3±0.04ms     4.9 MB/sec    1.00      8.2±0.06ms     5.0 MB/sec
formatter/numpy/ctypeslib.py               1.00  1629.1±27.23µs    10.2 MB/sec    1.00  1631.1±17.57µs    10.2 MB/sec
formatter/numpy/globals.py                 1.00    182.9±1.05µs    16.1 MB/sec    1.01    185.2±5.69µs    15.9 MB/sec
formatter/pydantic/types.py                1.01      3.5±0.08ms     7.4 MB/sec    1.00      3.4±0.05ms     7.4 MB/sec
linter/all-rules/large/dataset.py          1.02     10.6±0.09ms     3.8 MB/sec    1.00     10.4±0.26ms     3.9 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.01      2.8±0.01ms     6.0 MB/sec    1.00      2.7±0.00ms     6.1 MB/sec
linter/all-rules/numpy/globals.py          1.00    380.7±1.07µs     7.8 MB/sec    1.01    386.2±2.84µs     7.6 MB/sec
linter/all-rules/pydantic/types.py         1.01      4.8±0.05ms     5.3 MB/sec    1.00      4.7±0.02ms     5.4 MB/sec
linter/default-rules/large/dataset.py      1.00      5.3±0.03ms     7.6 MB/sec    1.01      5.4±0.02ms     7.6 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1133.2±5.32µs    14.7 MB/sec    1.01   1147.7±1.94µs    14.5 MB/sec
linter/default-rules/numpy/globals.py      1.00    129.1±0.52µs    22.9 MB/sec    1.02    131.1±2.21µs    22.5 MB/sec
linter/default-rules/pydantic/types.py     1.00      2.4±0.01ms    10.8 MB/sec    1.02      2.4±0.00ms    10.6 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.01     11.6±0.20ms     3.5 MB/sec    1.00     11.5±0.24ms     3.5 MB/sec
formatter/numpy/ctypeslib.py               1.01      2.3±0.04ms     7.4 MB/sec    1.00      2.2±0.05ms     7.5 MB/sec
formatter/numpy/globals.py                 1.00    250.8±7.76µs    11.8 MB/sec    1.02    255.6±7.29µs    11.5 MB/sec
formatter/pydantic/types.py                1.00      4.9±0.10ms     5.2 MB/sec    1.02      5.0±0.10ms     5.1 MB/sec
linter/all-rules/large/dataset.py          1.00     15.2±0.22ms     2.7 MB/sec    1.01     15.3±0.22ms     2.7 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      4.1±0.06ms     4.1 MB/sec    1.01      4.1±0.07ms     4.0 MB/sec
linter/all-rules/numpy/globals.py          1.00   504.2±10.69µs     5.9 MB/sec    1.02   512.2±10.69µs     5.8 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.9±0.13ms     3.7 MB/sec    1.01      7.0±0.11ms     3.7 MB/sec
linter/default-rules/large/dataset.py      1.00      8.0±0.18ms     5.1 MB/sec    1.03      8.3±0.10ms     4.9 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1661.5±33.19µs    10.0 MB/sec    1.02  1689.6±36.11µs     9.9 MB/sec
linter/default-rules/numpy/globals.py      1.00    189.5±5.52µs    15.6 MB/sec    1.02    194.1±4.14µs    15.2 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.5±0.06ms     7.2 MB/sec    1.03      3.6±0.08ms     7.0 MB/sec

@zanieb zanieb force-pushed the formatter/bool-op branch from 059661e to a5af31b Compare August 7, 2023 16:36
}

pub struct BoolOpLayout {
pub(crate) parentheses: Option<Parentheses>,
Copy link
Member Author

Choose a reason for hiding this comment

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

Unused. Will remove in follow-up pull request.

@zanieb zanieb marked this pull request as ready for review August 7, 2023 16:43
@zanieb zanieb added the formatter Related to the formatter label Aug 7, 2023
@MichaReiser
Copy link
Member

🙏

@zanieb zanieb merged commit 999d88e into main Aug 7, 2023
@zanieb zanieb deleted the formatter/bool-op branch August 7, 2023 17:22
durumu pushed a commit to durumu/ruff that referenced this pull request Aug 12, 2023
Closes astral-sh#6068

These commits are kind of a mess as I did some stumbling around here. 

Unrolls formatting of chained boolean operations to prevent nested
grouping which gives us Black-compatible formatting where each boolean
operation is on a new line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatter: boolean operator should have equal level
2 participants