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

Only omit optinal parens if the expression ends or starts with a parenthesized expression #5683

Conversation

MichaReiser
Copy link
Member

Summary

This PR matches Black' behavior where it only omits the optional parentheses if the expression starts or ends with a parenthesized expression:

a + [aaa, bbb, cccc] * c # Don't omit
[aaa, bbb, cccc] + a * c # Split
a + c * [aaa, bbb, ccc] # Split 

Test Plan

This improves the Jaccard index from 0.945 to 0.946

@MichaReiser
Copy link
Member Author

MichaReiser commented Jul 11, 2023

@MichaReiser MichaReiser force-pushed the comprehension-line-break branch from 7357591 to 3bce23a Compare July 11, 2023 11:30
@MichaReiser MichaReiser force-pushed the only-omit-optional-parens-if-expresison-starts-or-ends-with-parentheses branch from ef72a92 to 406c046 Compare July 11, 2023 11:30
@github-actions
Copy link
Contributor

github-actions bot commented Jul 11, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      8.4±0.02ms     4.8 MB/sec    1.02      8.6±0.02ms     4.8 MB/sec
formatter/numpy/ctypeslib.py               1.00  1911.3±20.16µs     8.7 MB/sec    1.00   1915.3±5.13µs     8.7 MB/sec
formatter/numpy/globals.py                 1.00    206.0±0.27µs    14.3 MB/sec    1.01    207.2±1.65µs    14.2 MB/sec
formatter/pydantic/types.py                1.00      4.3±0.01ms     6.0 MB/sec    1.00      4.3±0.01ms     5.9 MB/sec
linter/all-rules/large/dataset.py          1.00     14.1±0.03ms     2.9 MB/sec    1.00     14.1±0.10ms     2.9 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.5±0.00ms     4.7 MB/sec    1.00      3.5±0.02ms     4.7 MB/sec
linter/all-rules/numpy/globals.py          1.00    365.5±0.97µs     8.1 MB/sec    1.00    366.5±1.14µs     8.1 MB/sec
linter/all-rules/pydantic/types.py         1.01      6.3±0.04ms     4.0 MB/sec    1.00      6.3±0.03ms     4.1 MB/sec
linter/default-rules/large/dataset.py      1.00      7.2±0.02ms     5.7 MB/sec    1.00      7.2±0.06ms     5.7 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1488.2±2.81µs    11.2 MB/sec    1.00   1483.7±2.69µs    11.2 MB/sec
linter/default-rules/numpy/globals.py      1.00    159.6±0.28µs    18.5 MB/sec    1.01    160.6±1.02µs    18.4 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.2±0.01ms     8.0 MB/sec    1.00      3.2±0.04ms     7.9 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.01     12.6±0.50ms     3.2 MB/sec    1.00     12.5±0.47ms     3.3 MB/sec
formatter/numpy/ctypeslib.py               1.01      2.8±0.11ms     5.8 MB/sec    1.00      2.8±0.11ms     5.9 MB/sec
formatter/numpy/globals.py                 1.00   322.2±15.83µs     9.2 MB/sec    1.01   325.2±14.93µs     9.1 MB/sec
formatter/pydantic/types.py                1.00      6.2±0.37ms     4.1 MB/sec    1.00      6.2±0.27ms     4.1 MB/sec
linter/all-rules/large/dataset.py          1.06     22.2±0.62ms  1874.6 KB/sec    1.00     20.9±0.76ms  1990.0 KB/sec
linter/all-rules/numpy/ctypeslib.py        1.02      5.5±0.21ms     3.0 MB/sec    1.00      5.4±0.18ms     3.1 MB/sec
linter/all-rules/numpy/globals.py          1.01   652.2±32.35µs     4.5 MB/sec    1.00   645.8±25.25µs     4.6 MB/sec
linter/all-rules/pydantic/types.py         1.05      9.9±0.53ms     2.6 MB/sec    1.00      9.4±0.41ms     2.7 MB/sec
linter/default-rules/large/dataset.py      1.00     10.9±0.37ms     3.7 MB/sec    1.03     11.2±0.47ms     3.6 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00      2.2±0.13ms     7.5 MB/sec    1.01      2.3±0.11ms     7.4 MB/sec
linter/default-rules/numpy/globals.py      1.00   272.4±13.67µs    10.8 MB/sec    1.03   281.0±11.70µs    10.5 MB/sec
linter/default-rules/pydantic/types.py     1.00      4.9±0.19ms     5.2 MB/sec    1.00      4.9±0.18ms     5.2 MB/sec

@MichaReiser MichaReiser force-pushed the comprehension-line-break branch from 3bce23a to e83b302 Compare July 11, 2023 12:32
@MichaReiser MichaReiser force-pushed the only-omit-optional-parens-if-expresison-starts-or-ends-with-parentheses branch from 406c046 to ed3ad9e Compare July 11, 2023 12:32
@MichaReiser MichaReiser added the formatter Related to the formatter label Jul 11, 2023
@MichaReiser MichaReiser force-pushed the comprehension-line-break branch from e83b302 to 6e5dc7b Compare July 11, 2023 14:41
@MichaReiser MichaReiser force-pushed the only-omit-optional-parens-if-expresison-starts-or-ends-with-parentheses branch from ed3ad9e to 31505b3 Compare July 11, 2023 14:41
Base automatically changed from comprehension-line-break to main July 11, 2023 14:51
@MichaReiser
Copy link
Member Author

Graphite rebased this pull request as part of a merge.

@MichaReiser MichaReiser force-pushed the only-omit-optional-parens-if-expresison-starts-or-ends-with-parentheses branch from 31505b3 to 66184e2 Compare July 11, 2023 14:58
@MichaReiser MichaReiser merged commit 30bec3f into main Jul 11, 2023
@MichaReiser MichaReiser deleted the only-omit-optional-parens-if-expresison-starts-or-ends-with-parentheses branch July 11, 2023 15:05
@MichaReiser
Copy link
Member Author

@MichaReiser merged this pull request with Graphite.

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.

2 participants