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

# fmt: pass - ignore formatting for single statements #1162

Closed
mrgnw opened this issue Nov 18, 2019 · 5 comments · Fixed by #1800
Closed

# fmt: pass - ignore formatting for single statements #1162

mrgnw opened this issue Nov 18, 2019 · 5 comments · Fixed by #1800
Labels
T: enhancement New feature or request

Comments

@mrgnw
Copy link

mrgnw commented Nov 18, 2019

Feature request:
# fmt: pass would skip formatting for the single statement that immediately follows.

Is your feature request related to a problem? Please describe.

Not a response to a problem but it might be helpful for the following reasons:

  • Easier to use / less typing
  • Can't forget to turn it back on
    • Or accidentally insert code you do want formatted into an unformatted block
  • Encourages ignoring less code
    • One-offs are always isolated to one statement instead of potentially large chunks of code.

Describe the solution you'd like

z = "hello " + "world"

# fmt: pass
custom_formatting = [
    0,  1,  2,
    3,  4,  5,
    6,  7,  8,
]

regular_formatting = [
   0,  1,  2,  'this will be formatted'
]

The custom_formatting list would be ignored, everything else would be formatted.

Describe alternatives you've considered

  1. Current solution
# fmt: off
ugly_code=('but I want it this way')
even_more=('dont\'t judge me')
# fmt: on
  1. #fmt: off at end of line (Should # fmt: off be allowed as an inline comment? #790)
    I believe # fmt: pass addresses the same concern while also being a bit more flexible.
    • a single statement could be multi-line
    • a long line would bury an inline comment
    • # fmt: pass is more readable & predictable as a separate line
  2. Disable formatting for certain expressions only. Disable formatting for certain expressions only. #798
  3. Deal with it

Additional context

Naming:

  • # fmt: pass reflects Python's existing pass statement. Hopefully this hints that you can use it to temporarily appease the formatter for one quick thing, but it's not something you want everywhere.

  • Naming could be anything, e.g. "pass", "skip", "ignore"

@mrgnw mrgnw added the T: enhancement New feature or request label Nov 18, 2019
@vitalik
Copy link

vitalik commented Mar 10, 2020

I like this one..

but would like to extend it a bit more

foo = bar.<100 characters +> # fmt: pass

if i place at the end of the statement - it should work as well (not only before the statement)

@saroad2
Copy link
Contributor

saroad2 commented May 12, 2020

I would love to see this feature merged!

@rbarrette
Copy link

rbarrette commented May 23, 2020

I like this one..

but would like to extend it a bit more

foo = bar.<100 characters +> # fmt: pass

if i place at the end of the statement - it should work as well (not only before the statement)

Expanding on @vitalik's ask. It would be great if this feature would be compatible with other inline comment options.

def example(self): #noqa - squelch some lint check # fmt: pass

@prashanth-sams
Copy link

The reason why I uninstalled black :(

@clragon
Copy link

clragon commented Oct 14, 2020

We definitly need something like this.

I have ansible vars in my python script
which require me to write something like
{{ variable_name }} which black will turn into {{variable_name}}
which afaik isnt valid anymore.

turning the line into

# fmt: off
my_var = {{ variable_name }}
# fmt: on

looks very ugly in my opinion.
this however:
my_var = {{ variable_name }} # fmt: skip
would look quite okay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants