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

Trailing own line comments before func or class #4921

Merged
merged 1 commit into from
Jun 8, 2023

Conversation

MichaReiser
Copy link
Member

Summary

This PR adds special handling for own line comments between a statement and a function or class definition on the module level.

some = statement
# This should be stick to the statement above


# This should be split from the above by two lines
class MyClassWithComplexLeadingComments:
    pass

By default, the # This should be stick to the statement above would become a leading comment
of the class AND the Suite formatting separates the comment by two empty lines from the
previous statement, so that the result becomes:

some = statement


#  This should be stick to the statement above


# This should be split from the above by two lines
class MyClassWithComplexLeadingComments:
     pass

Which is not what we want. The work around is to make the # This should be stick to the statement above
a trailing comment of the previous statement.

Test Plan

You can see that this case is now correctly covered in the Black comments9.py test case

@MichaReiser MichaReiser force-pushed the replace-verbatim-with-not-yet-implemented branch from 59c3e35 to 48ce57f Compare June 7, 2023 12:49
Base automatically changed from replace-verbatim-with-not-yet-implemented to main June 7, 2023 12:57
@MichaReiser MichaReiser force-pushed the trailing-comment-before-func-or-class branch from bb0517f to 2448287 Compare June 7, 2023 14:14
@github-actions
Copy link
Contributor

github-actions bot commented Jun 7, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      5.4±0.02ms     7.6 MB/sec    1.00      5.4±0.03ms     7.6 MB/sec
formatter/numpy/ctypeslib.py               1.00   1071.6±3.26µs    15.5 MB/sec    1.00   1075.4±9.25µs    15.5 MB/sec
formatter/numpy/globals.py                 1.01    125.7±1.37µs    23.5 MB/sec    1.00    124.7±0.13µs    23.7 MB/sec
formatter/pydantic/types.py                1.01      2.4±0.01ms    10.5 MB/sec    1.00      2.4±0.01ms    10.6 MB/sec
linter/all-rules/large/dataset.py          1.01     14.2±0.53ms     2.9 MB/sec    1.00     14.0±0.09ms     2.9 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.4±0.01ms     5.0 MB/sec    1.01      3.4±0.02ms     4.9 MB/sec
linter/all-rules/numpy/globals.py          1.00    418.2±0.42µs     7.1 MB/sec    1.01    420.7±0.47µs     7.0 MB/sec
linter/all-rules/pydantic/types.py         1.00      5.8±0.01ms     4.4 MB/sec    1.00      5.9±0.01ms     4.4 MB/sec
linter/default-rules/large/dataset.py      1.00      6.8±0.02ms     6.0 MB/sec    1.00      6.7±0.02ms     6.0 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1457.2±3.56µs    11.4 MB/sec    1.01  1467.0±11.39µs    11.4 MB/sec
linter/default-rules/numpy/globals.py      1.00    161.5±0.23µs    18.3 MB/sec    1.00    161.8±4.26µs    18.2 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.0±0.00ms     8.4 MB/sec    1.00      3.0±0.02ms     8.4 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.21      6.1±0.04ms     6.7 MB/sec    1.00      5.0±0.03ms     8.1 MB/sec
formatter/numpy/ctypeslib.py               1.18  1142.4±11.59µs    14.6 MB/sec    1.00   968.6±14.46µs    17.2 MB/sec
formatter/numpy/globals.py                 1.09    123.4±1.30µs    23.9 MB/sec    1.00    113.3±2.59µs    26.1 MB/sec
formatter/pydantic/types.py                1.17      2.6±0.02ms     9.8 MB/sec    1.00      2.2±0.03ms    11.4 MB/sec
linter/all-rules/large/dataset.py          1.02     12.5±0.17ms     3.2 MB/sec    1.00     12.3±0.10ms     3.3 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.02      3.2±0.03ms     5.2 MB/sec    1.00      3.2±0.02ms     5.3 MB/sec
linter/all-rules/numpy/globals.py          1.02    324.7±8.10µs     9.1 MB/sec    1.00    317.4±4.18µs     9.3 MB/sec
linter/all-rules/pydantic/types.py         1.01      5.3±0.09ms     4.8 MB/sec    1.00      5.3±0.06ms     4.8 MB/sec
linter/default-rules/large/dataset.py      1.02      6.2±0.06ms     6.5 MB/sec    1.00      6.1±0.03ms     6.6 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.01  1287.2±18.48µs    12.9 MB/sec    1.00  1280.3±10.60µs    13.0 MB/sec
linter/default-rules/numpy/globals.py      1.00    135.7±1.41µs    21.7 MB/sec    1.01    136.6±1.85µs    21.6 MB/sec
linter/default-rules/pydantic/types.py     1.00      2.8±0.02ms     9.1 MB/sec    1.00      2.8±0.04ms     9.2 MB/sec

@MichaReiser MichaReiser force-pushed the trailing-comment-before-func-or-class branch from 2448287 to 5a9709d Compare June 8, 2023 05:51
@MichaReiser MichaReiser changed the base branch from main to include-parentheses-in-arguments-range June 8, 2023 05:51
@MichaReiser MichaReiser mentioned this pull request Jun 8, 2023
Base automatically changed from include-parentheses-in-arguments-range to main June 8, 2023 05:53
@MichaReiser MichaReiser added internal An internal refactor or improvement formatter Related to the formatter labels Jun 8, 2023
@MichaReiser MichaReiser force-pushed the trailing-comment-before-func-or-class branch from 5a9709d to 894b045 Compare June 8, 2023 05:57
@MichaReiser MichaReiser changed the base branch from main to basic-const-formatting June 8, 2023 10:58
@MichaReiser MichaReiser force-pushed the trailing-comment-before-func-or-class branch from 894b045 to f5240f7 Compare June 8, 2023 10:58
@MichaReiser MichaReiser requested a review from konstin June 8, 2023 10:58
@MichaReiser MichaReiser force-pushed the basic-const-formatting branch from bab81d7 to f42af55 Compare June 8, 2023 11:05
@MichaReiser MichaReiser force-pushed the trailing-comment-before-func-or-class branch from f5240f7 to 1b58a53 Compare June 8, 2023 11:05
Base automatically changed from basic-const-formatting to main June 8, 2023 11:42
@MichaReiser MichaReiser force-pushed the trailing-comment-before-func-or-class branch from 1b58a53 to 6a13e21 Compare June 8, 2023 11:44
@MichaReiser MichaReiser enabled auto-merge (squash) June 8, 2023 11:44
@MichaReiser MichaReiser closed this Jun 8, 2023
auto-merge was automatically disabled June 8, 2023 12:44

Pull request was closed

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.

2 participants