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

Track formatting all comments #6178

Merged
merged 1 commit into from
Aug 10, 2023
Merged

Conversation

konstin
Copy link
Member

@konstin konstin commented Jul 30, 2023

We currently don't format all comments as match statements are not yet implemented. We can work around this for the top level match statement by setting them manually formatted but the mocked-out top level match doesn't call into its children so they would still have unformatted comments

@github-actions
Copy link
Contributor

github-actions bot commented Jul 30, 2023

PR Check Results

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      8.2±0.09ms     4.9 MB/sec    1.00      8.3±0.10ms     4.9 MB/sec
formatter/numpy/ctypeslib.py               1.01  1647.0±38.73µs    10.1 MB/sec    1.00  1633.4±11.28µs    10.2 MB/sec
formatter/numpy/globals.py                 1.02    187.6±7.25µs    15.7 MB/sec    1.00    184.5±2.58µs    16.0 MB/sec
formatter/pydantic/types.py                1.00      3.5±0.09ms     7.3 MB/sec    1.01      3.5±0.12ms     7.2 MB/sec
linter/all-rules/large/dataset.py          1.00     10.2±0.04ms     4.0 MB/sec    1.00     10.2±0.06ms     4.0 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      2.7±0.01ms     6.1 MB/sec    1.00      2.7±0.02ms     6.1 MB/sec
linter/all-rules/numpy/globals.py          1.00    383.0±0.87µs     7.7 MB/sec    1.00    382.2±0.66µs     7.7 MB/sec
linter/all-rules/pydantic/types.py         1.00      5.3±0.07ms     4.8 MB/sec    1.00      5.3±0.02ms     4.8 MB/sec
linter/default-rules/large/dataset.py      1.01      5.3±0.01ms     7.6 MB/sec    1.00      5.3±0.02ms     7.7 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.01   1151.5±3.99µs    14.5 MB/sec    1.00   1144.3±2.90µs    14.6 MB/sec
linter/default-rules/numpy/globals.py      1.00    132.7±2.34µs    22.2 MB/sec    1.00    132.1±1.60µs    22.3 MB/sec
linter/default-rules/pydantic/types.py     1.00      2.4±0.01ms    10.6 MB/sec    1.00      2.4±0.02ms    10.7 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00     11.9±0.29ms     3.4 MB/sec    1.01     12.0±0.28ms     3.4 MB/sec
formatter/numpy/ctypeslib.py               1.00      2.3±0.07ms     7.3 MB/sec    1.03      2.3±0.13ms     7.1 MB/sec
formatter/numpy/globals.py                 1.00   255.3±11.24µs    11.6 MB/sec    1.01   257.0±12.29µs    11.5 MB/sec
formatter/pydantic/types.py                1.00      5.0±0.15ms     5.1 MB/sec    1.01      5.1±0.16ms     5.0 MB/sec
linter/all-rules/large/dataset.py          1.00     15.0±0.28ms     2.7 MB/sec    1.02     15.2±0.44ms     2.7 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      4.1±0.12ms     4.0 MB/sec    1.01      4.1±0.10ms     4.0 MB/sec
linter/all-rules/numpy/globals.py          1.00   512.6±14.51µs     5.8 MB/sec    1.01   515.7±17.90µs     5.7 MB/sec
linter/all-rules/pydantic/types.py         1.00      7.8±0.18ms     3.3 MB/sec    1.01      7.8±0.16ms     3.3 MB/sec
linter/default-rules/large/dataset.py      1.00      8.1±0.15ms     5.0 MB/sec    1.01      8.2±0.13ms     5.0 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1697.9±37.91µs     9.8 MB/sec    1.01  1712.2±64.73µs     9.7 MB/sec
linter/default-rules/numpy/globals.py      1.00   195.9±11.93µs    15.1 MB/sec    1.02   199.6±10.26µs    14.8 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.6±0.07ms     7.0 MB/sec    1.00      3.6±0.09ms     7.1 MB/sec

@@ -180,6 +180,17 @@ impl Format<PyFormatContext<'_>> for NotYetImplemented {
})?;

f.write_element(FormatElement::Tag(Tag::EndVerbatim))?;

let comments = f.context().comments().clone();
Copy link
Member

Choose a reason for hiding this comment

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

You could implement your own PreorderVisitor that marks the comments of all children as formatted. We probably need something similar for fmt: skip anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

i'll wait until we have match statement formatting instead

@MichaReiser MichaReiser added the formatter Related to the formatter label Aug 8, 2023
@MichaReiser MichaReiser changed the base branch from main to any-node-ref-visit-preorder August 8, 2023 15:16
@MichaReiser MichaReiser force-pushed the track_formatting_all_comments branch from d7bfa62 to a132a7c Compare August 8, 2023 15:16
@MichaReiser
Copy link
Member

MichaReiser commented Aug 8, 2023

@MichaReiser MichaReiser force-pushed the track_formatting_all_comments branch from a132a7c to 2f771c2 Compare August 8, 2023 15:19
@@ -24,7 +24,17 @@ impl FormatNodeRule<MatchCase> for FormatMatchCase {
[
text("case"),
space(),
not_yet_implemented_custom_text("NOT_YET_IMPLEMENTED_Pattern"),
format_with(|f: &mut PyFormatter| {
Copy link
Member

Choose a reason for hiding this comment

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

This is intentionally ugly to make sure we remove we don't forget to remove the comment.mark_formatted when replacing this with pattern.format()

@MichaReiser MichaReiser marked this pull request as ready for review August 8, 2023 15:24
@MichaReiser
Copy link
Member

Can I now approve my own PR 😅

@konstin
Copy link
Member Author

konstin commented Aug 8, 2023

¯\_(ツ)_/¯

@konstin
Copy link
Member Author

konstin commented Aug 8, 2023

so who'll merge?

@MichaReiser
Copy link
Member

I can take care of merging since we have to coordinate with the downstream PRs. All I need is a thumbs up/down from you.

@konstin
Copy link
Member Author

konstin commented Aug 9, 2023

👍

@MichaReiser MichaReiser changed the base branch from any-node-ref-visit-preorder to fstring-comments August 9, 2023 08:59
@MichaReiser MichaReiser force-pushed the track_formatting_all_comments branch from 2f771c2 to 20dabc8 Compare August 9, 2023 08:59
Base automatically changed from fstring-comments to main August 10, 2023 07:11
We currently don't format all comments as match statements are not yet implemented. We can work around this for the top level match statement by setting them manually formatted but the mocked-out top level match doesn't call into its children so they would still have unformatted comments
@MichaReiser
Copy link
Member

Graphite rebased this pull request as part of a merge.

@MichaReiser MichaReiser merged commit 39beeb6 into main Aug 10, 2023
16 checks passed
@MichaReiser MichaReiser deleted the track_formatting_all_comments branch August 10, 2023 07:19
@MichaReiser
Copy link
Member

@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