Skip to content

Format BoolOp#4986

Merged
MichaReiser merged 2 commits intomainfrom
format-bool-op
Jun 21, 2023
Merged

Format BoolOp#4986
MichaReiser merged 2 commits intomainfrom
format-bool-op

Conversation

@MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jun 9, 2023

Summary

This PR implements basic formatting for boolean operations.

Boolean operations (a and b) are formatted similar to binary expressions (a + b) if they only have two operands. I extracted the common logic into a FormatBinaryLike struct.

Test Plan

I added a new test file that tests the different variants.

@MichaReiser
Copy link
Member Author

MichaReiser commented Jun 9, 2023

@MichaReiser MichaReiser added internal An internal refactor or improvement formatter Related to the formatter labels Jun 9, 2023
@MichaReiser MichaReiser linked an issue Jun 9, 2023 that may be closed by this pull request
@MichaReiser MichaReiser force-pushed the format-bool-op branch 2 times, most recently from 6375287 to ea45020 Compare June 9, 2023 16:17
@github-actions
Copy link
Contributor

github-actions bot commented Jun 9, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      6.9±0.04ms     5.9 MB/sec    1.00      6.9±0.02ms     5.9 MB/sec
formatter/numpy/ctypeslib.py               1.01   1385.3±2.44µs    12.0 MB/sec    1.00   1373.0±2.06µs    12.1 MB/sec
formatter/numpy/globals.py                 1.00    132.8±0.24µs    22.2 MB/sec    1.00    133.4±0.23µs    22.1 MB/sec
formatter/pydantic/types.py                1.01      2.8±0.01ms     9.2 MB/sec    1.00      2.8±0.01ms     9.2 MB/sec
linter/all-rules/large/dataset.py          1.00     13.8±0.07ms     2.9 MB/sec    1.00     13.9±0.07ms     2.9 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.4±0.02ms     4.8 MB/sec    1.02      3.5±0.01ms     4.8 MB/sec
linter/all-rules/numpy/globals.py          1.00    361.5±1.25µs     8.2 MB/sec    1.00    362.6±0.73µs     8.1 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.1±0.04ms     4.2 MB/sec    1.00      6.1±0.03ms     4.2 MB/sec
linter/default-rules/large/dataset.py      1.00      7.0±0.03ms     5.8 MB/sec    1.01      7.1±0.03ms     5.7 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1466.7±2.12µs    11.4 MB/sec    1.00   1472.2±8.98µs    11.3 MB/sec
linter/default-rules/numpy/globals.py      1.00    155.1±0.29µs    19.0 MB/sec    1.01    156.7±0.40µs    18.8 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.2±0.01ms     8.0 MB/sec    1.01      3.2±0.02ms     8.0 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.02      9.6±0.32ms     4.3 MB/sec    1.00      9.4±0.39ms     4.3 MB/sec
formatter/numpy/ctypeslib.py               1.03  1963.4±92.54µs     8.5 MB/sec    1.00  1910.0±71.51µs     8.7 MB/sec
formatter/numpy/globals.py                 1.02   197.7±15.68µs    14.9 MB/sec    1.00   193.6±15.15µs    15.2 MB/sec
formatter/pydantic/types.py                1.04      3.9±0.16ms     6.5 MB/sec    1.00      3.8±0.15ms     6.7 MB/sec
linter/all-rules/large/dataset.py          1.00     19.1±0.50ms     2.1 MB/sec    1.00     19.1±0.49ms     2.1 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.01      5.1±0.18ms     3.2 MB/sec    1.00      5.1±0.18ms     3.3 MB/sec
linter/all-rules/numpy/globals.py          1.02   621.6±23.19µs     4.7 MB/sec    1.00   608.7±32.13µs     4.8 MB/sec
linter/all-rules/pydantic/types.py         1.00      8.4±0.27ms     3.0 MB/sec    1.01      8.6±0.31ms     3.0 MB/sec
linter/default-rules/large/dataset.py      1.01      9.9±0.24ms     4.1 MB/sec    1.00      9.8±0.28ms     4.1 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.01      2.2±0.17ms     7.7 MB/sec    1.00      2.2±0.07ms     7.7 MB/sec
linter/default-rules/numpy/globals.py      1.00   248.8±21.02µs    11.9 MB/sec    1.02   254.2±16.43µs    11.6 MB/sec
linter/default-rules/pydantic/types.py     1.00      4.5±0.21ms     5.7 MB/sec    1.00      4.5±0.27ms     5.7 MB/sec

@MichaReiser MichaReiser force-pushed the more-bin-op-formatting branch 4 times, most recently from a39dded to d785d44 Compare June 19, 2023 15:55
@MichaReiser MichaReiser mentioned this pull request Jun 19, 2023
@MichaReiser MichaReiser force-pushed the more-bin-op-formatting branch from d785d44 to 5c30e73 Compare June 20, 2023 07:45
@MichaReiser MichaReiser mentioned this pull request Jun 20, 2023
@MichaReiser MichaReiser changed the base branch from more-bin-op-formatting to format-unary-expr June 20, 2023 16:00
@MichaReiser MichaReiser force-pushed the format-bool-op branch 2 times, most recently from 3eca4fd to 96c0de8 Compare June 20, 2023 16:21
@MichaReiser MichaReiser force-pushed the format-bool-op branch 2 times, most recently from 1b1cc52 to aacef91 Compare June 20, 2023 20:37

match layout {
BinaryLayout::Default => self.fmt_default(f),
BinaryLayout::ExpandLeft => {
Copy link
Member Author

Choose a reason for hiding this comment

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

The IR is unchanged and has been moved from expr_bin_op

@MichaReiser MichaReiser marked this pull request as ready for review June 21, 2023 06:25
Base automatically changed from format-unary-expr to main June 21, 2023 08:09
@MichaReiser MichaReiser enabled auto-merge (squash) June 21, 2023 09:19
@MichaReiser MichaReiser merged commit 653dbb6 into main Jun 21, 2023
@MichaReiser MichaReiser deleted the format-bool-op branch June 21, 2023 09:27
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: BoolOp

2 participants