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

Unable to format ignored decorator in class #718

Closed
USSRLivesOn opened this issue Feb 19, 2019 · 4 comments
Closed

Unable to format ignored decorator in class #718

USSRLivesOn opened this issue Feb 19, 2019 · 4 comments
Labels
C: invalid code Black destroyed a valid Python file T: bug Something isn't working

Comments

@USSRLivesOn
Copy link

Operating system: MacOS 10.14.3
Python version: 3.6.6
Black version: 18.9b0
Does also happen on master: Yes

Input:

class MyClass:

    # fmt: off
    @mydecorator
    # fmt: on
    def test_decorated(self):
        pass

foo = 'foo'

Result:
INTERNAL ERROR: Black produced code that is not equivalent to the source. Please report a bug on https://github.com/ambv/black/issues. This diff might be helpful: /var/folders/d6/wn1mqq2j05n50jjvrtk94scr0000gn/T/blk_xq234z_q.log

This is the minimal reproducing case I could reduce it to. Not exactly sure where the issue is, but I figured it would be helpful to file. Thanks for working on Black!

@zsol
Copy link
Collaborator

zsol commented Feb 20, 2019

Looks like the indentation is messed up after # fmt: on in this case.

input:

class X:
  # fmt: off
  @lol
  # fmt: on
  def f():
    pass
f = 'f'

output:

class X:
    # fmt: off
  @lol
  # fmt: on
  def f():
    pass
    f = "f"

@zsol zsol added T: bug Something isn't working C: invalid code Black destroyed a valid Python file labels Feb 20, 2019
@pawelad
Copy link

pawelad commented Mar 9, 2019

Just encountered the same problem when trying to tell black not to format Click decorators but do format the rest of the file:

# fmt: off
@click.command()
@click.option(
    "--interactive", "-i",
    is_flag=True, default=False, show_default=True,
    help="Open the browser.",
)
# fmt: on
def foo(interactive):
	# Some ugly code here

@pawelad
Copy link

pawelad commented Mar 9, 2019

Actually, mine seems to be a duplicate of #560 - not sure if they're the same / related. Sorry for posting in the wrong thread if they're not.

@zsol
Copy link
Collaborator

zsol commented Jun 28, 2019

Yep.
Duplicate of #560

@zsol zsol closed this as completed Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: invalid code Black destroyed a valid Python file T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants