Closed
Description
Operating system: Linux Mint 19.0
Python version: 3.6.6
Black version: 18.9b0
Does also happen on master: yes
Simplest reproducer: the following is left unchanged. In fact, it behaves as if # fmt: off
is true until end of file.
# fmt: off
if (x and y):
# fmt: on
pass
if (x and y):
pass
The soonest # fmt: on
takes effect is at end of the indented if
block.
Ran into this with a series of decorators:
# fmt: off
@click.command()
@click.option("-a", "--align", help="aligned help texts")
@click.option("-b", "--big-option", help="should stay aligned")
# fmt: on
def foo(align, big_option):
pass
Simple workaround for me is keep the formatter commands within a "block" - the following works perfectly fine:
@click.command()
# fmt: off
@click.option("-a", "--align", help="aligned help texts")
@click.option("-b", "--big-option", help="should stay aligned")
# fmt: on
def foo(align, big_option):
pass
Metadata
Metadata
Assignees
Labels
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
matejcik commentedon Oct 12, 2018
I don't know if this is even fixable in the general case.
What I find problematic, though, is that a
# fmt: on
directive is silently ignored. In case black can't recover from a weirdly placed# fmt: on
, that should be a loud error, IMHO.ambv commentedon Oct 17, 2018
Thanks for your report, we'll tackle this for the next release.
Carreau commentedon May 28, 2019
Got same issue but for a flipped on/off:
Where I only want to reformat some part of the code., and all the end of the file got reformatted.
[-]"fmt: on" does not work when crossing block boundaries[/-][+]"fmt: on" does not work when crossing block boundaries and decorators[/+]cooperlees commentedon May 9, 2020
PR merged. Thanks!
8 remaining items