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

Add trailing comma for single-element import-from groups #6583

Merged
merged 1 commit into from
Aug 15, 2023

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Aug 15, 2023

Summary

Unlike other statements, Black always adds a trailing comma if an import-from statement breaks with a single import member. I believe this is for compatibility with isort -- see psf/black@09f5ee3, psf/black#127, or https://github.com/psf/black/blob/66648c528a95553c1f822ece394ac98784baee47/src/black/linegen.py#L1452 for the current version.

Test Plan

cargo test, notice that a big chunk of the compatibility suite is removed.

Before:

project similarity index
cpython 0.75472
django 0.99804
transformers 0.99618
twine 0.99876
typeshed 0.74233
warehouse 0.99601
zulip 0.99727

After:

project similarity index
cpython 0.75472
django 0.99804
transformers 0.99618
twine 0.99876
typeshed 0.74260
warehouse 0.99601
zulip 0.99727

@charliermarsh charliermarsh added the formatter Related to the formatter label Aug 15, 2023
@github-actions
Copy link
Contributor

PR Check Results

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      4.5±0.04ms     9.0 MB/sec    1.02      4.6±0.04ms     8.8 MB/sec
formatter/numpy/ctypeslib.py               1.00    913.7±3.55µs    18.2 MB/sec    1.01    926.4±4.11µs    18.0 MB/sec
formatter/numpy/globals.py                 1.00     93.1±0.43µs    31.7 MB/sec    1.01     94.2±0.47µs    31.3 MB/sec
formatter/pydantic/types.py                1.00  1846.7±11.72µs    13.8 MB/sec    1.01  1870.1±32.57µs    13.6 MB/sec
linter/all-rules/large/dataset.py          1.00     12.2±0.04ms     3.3 MB/sec    1.00     12.2±0.03ms     3.3 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.3±0.01ms     5.1 MB/sec    1.00      3.3±0.02ms     5.1 MB/sec
linter/all-rules/numpy/globals.py          1.00    462.8±0.60µs     6.4 MB/sec    1.00    464.1±7.41µs     6.4 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.3±0.02ms     4.0 MB/sec    1.00      6.3±0.03ms     4.0 MB/sec
linter/default-rules/large/dataset.py      1.00      6.5±0.02ms     6.3 MB/sec    1.01      6.5±0.07ms     6.3 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1434.1±11.36µs    11.6 MB/sec    1.00  1427.1±21.51µs    11.7 MB/sec
linter/default-rules/numpy/globals.py      1.00    168.9±1.86µs    17.5 MB/sec    1.00    168.9±5.98µs    17.5 MB/sec
linter/default-rules/pydantic/types.py     1.00      2.9±0.01ms     8.7 MB/sec    1.00      2.9±0.01ms     8.8 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.01      4.2±0.10ms     9.7 MB/sec    1.00      4.2±0.08ms     9.8 MB/sec
formatter/numpy/ctypeslib.py               1.00   791.9±13.15µs    21.0 MB/sec    1.00   788.2±11.42µs    21.1 MB/sec
formatter/numpy/globals.py                 1.01     80.7±2.25µs    36.6 MB/sec    1.00     80.1±1.62µs    36.8 MB/sec
formatter/pydantic/types.py                1.00  1652.4±55.11µs    15.4 MB/sec    1.00  1645.8±28.71µs    15.5 MB/sec
linter/all-rules/large/dataset.py          1.00     12.7±0.10ms     3.2 MB/sec    1.01     12.8±0.19ms     3.2 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.5±0.02ms     4.7 MB/sec    1.01      3.6±0.03ms     4.7 MB/sec
linter/all-rules/numpy/globals.py          1.01    378.5±9.13µs     7.8 MB/sec    1.00    376.6±6.35µs     7.8 MB/sec
linter/all-rules/pydantic/types.py         1.02      6.7±0.20ms     3.8 MB/sec    1.00      6.6±0.06ms     3.9 MB/sec
linter/default-rules/large/dataset.py      1.00      7.0±0.06ms     5.8 MB/sec    1.00      7.0±0.05ms     5.8 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.01  1484.3±79.43µs    11.2 MB/sec    1.00  1465.1±20.57µs    11.4 MB/sec
linter/default-rules/numpy/globals.py      1.01    154.2±5.00µs    19.1 MB/sec    1.00    152.5±2.14µs    19.3 MB/sec
linter/default-rules/pydantic/types.py     1.01      3.2±0.04ms     8.0 MB/sec    1.00      3.1±0.06ms     8.1 MB/sec

@charliermarsh charliermarsh merged commit b1c4c7b into main Aug 15, 2023
@charliermarsh charliermarsh deleted the charlie/imports branch August 15, 2023 11:15
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