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 import statements #5493

Merged
merged 4 commits into from
Jul 4, 2023
Merged

Format import statements #5493

merged 4 commits into from
Jul 4, 2023

Conversation

konstin
Copy link
Member

@konstin konstin commented Jul 3, 2023

Summary

Format import statements in all their variants. Specifically, this implemented formatting StmtImport, StmtImportFrom and Alias.

Test Plan

I added some custom snapshots, even though this has been covered well by black's tests.

@konstin
Copy link
Member Author

konstin commented Jul 3, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@konstin konstin mentioned this pull request Jul 3, 2023
72 tasks
text("from"),
space(),
dynamic_text(&level_str, None),
module.as_ref().map(AsFormat::format),
Copy link
Member Author

@konstin konstin Jul 3, 2023

Choose a reason for hiding this comment

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

i was surprised there wasn't a blanket Option<T>: T: AsFormat impl for .format()

Copy link
Member

Choose a reason for hiding this comment

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

I think I ran into issues when I tried adding it last time because Rust doesn't know that T doesn't implement Format and AsFormat at the same time

@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      8.9±0.15ms     4.6 MB/sec    1.01      9.0±0.15ms     4.5 MB/sec
formatter/numpy/ctypeslib.py               1.01      2.0±0.03ms     8.2 MB/sec    1.00      2.0±0.05ms     8.3 MB/sec
formatter/numpy/globals.py                 1.00    220.9±5.87µs    13.4 MB/sec    1.03    228.0±6.78µs    12.9 MB/sec
formatter/pydantic/types.py                1.02      4.4±0.07ms     5.8 MB/sec    1.00      4.3±0.08ms     5.9 MB/sec
linter/all-rules/large/dataset.py          1.00     15.3±0.20ms     2.7 MB/sec    1.00     15.2±0.21ms     2.7 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.8±0.07ms     4.4 MB/sec    1.01      3.8±0.06ms     4.3 MB/sec
linter/all-rules/numpy/globals.py          1.01   489.5±10.62µs     6.0 MB/sec    1.00   486.4±11.25µs     6.1 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.7±0.13ms     3.8 MB/sec    1.01      6.7±0.11ms     3.8 MB/sec
linter/default-rules/large/dataset.py      1.00      7.6±0.11ms     5.3 MB/sec    1.01      7.7±0.11ms     5.3 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.01  1673.8±23.90µs     9.9 MB/sec    1.00  1655.4±25.96µs    10.1 MB/sec
linter/default-rules/numpy/globals.py      1.00    184.8±4.08µs    16.0 MB/sec    1.10    204.1±9.20µs    14.5 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.4±0.06ms     7.4 MB/sec    1.01      3.5±0.05ms     7.3 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      9.6±0.18ms     4.3 MB/sec    1.03      9.8±0.26ms     4.2 MB/sec
formatter/numpy/ctypeslib.py               1.00      2.1±0.04ms     8.0 MB/sec    1.01      2.1±0.08ms     7.9 MB/sec
formatter/numpy/globals.py                 1.00    235.3±5.54µs    12.5 MB/sec    1.02   239.7±12.68µs    12.3 MB/sec
formatter/pydantic/types.py                1.00      4.6±0.10ms     5.5 MB/sec    1.00      4.7±0.14ms     5.5 MB/sec
linter/all-rules/large/dataset.py          1.00     16.9±0.24ms     2.4 MB/sec    1.01     17.1±0.40ms     2.4 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      4.3±0.09ms     3.8 MB/sec    1.03      4.5±0.15ms     3.7 MB/sec
linter/all-rules/numpy/globals.py          1.00   511.4±12.77µs     5.8 MB/sec    1.01   516.1±14.31µs     5.7 MB/sec
linter/all-rules/pydantic/types.py         1.00      7.4±0.19ms     3.5 MB/sec    1.02      7.5±0.20ms     3.4 MB/sec
linter/default-rules/large/dataset.py      1.00      8.6±0.16ms     4.8 MB/sec    1.01      8.6±0.18ms     4.7 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1811.1±50.77µs     9.2 MB/sec    1.00  1806.6±48.48µs     9.2 MB/sec
linter/default-rules/numpy/globals.py      1.00    208.1±4.82µs    14.2 MB/sec    1.01    210.0±7.05µs    14.1 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.8±0.05ms     6.7 MB/sec    1.00      3.8±0.08ms     6.7 MB/sec

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.

Niiiceee!

+
+
+def spam() -> None:
+ ...
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to this PR: interesting, black sometimes keeps the single statement formatting

@konstin konstin enabled auto-merge (squash) July 4, 2023 06:56
@konstin konstin merged commit 787e2fd into main Jul 4, 2023
@konstin konstin deleted the format_imports branch July 4, 2023 07:07
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.

2 participants