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

Minimal file produces invalid code #1369

Closed
codyd51 opened this issue Apr 29, 2020 · 2 comments
Closed

Minimal file produces invalid code #1369

codyd51 opened this issue Apr 29, 2020 · 2 comments
Labels
R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@codyd51
Copy link

codyd51 commented Apr 29, 2020

Describe the bug Under certain circumstances, annotating a method with # yapf: disable among other inputs causes black to produce invalid code.

To Reproduce Steps to reproduce the behavior:

Minimal reproducing input:

class BaseClass1:
    # yapf: disable
    def method1(self):
        pass


class BaseClass2:
    # yapf: disable
    def method2(self):
        pass


class Mixin(BaseClass1, BaseClass2):
    pass
$ black bad_input.py
error: cannot format bad_input.py: INTERNAL ERROR: Black produced invalid code: expected an indented block (<unknown>, line 8). Please report a bug on https://github.com/ambv/black/issues.  This invalid output might be helpful: /var/folders/y0/clprvktj3b5__hkvm2p4m_yr0000gn/T/blk_8rbcsejt.log
All done! 💥 💔 💥
1 file failed to reformat.

Here's the associated logfile: blk_8rbcsejt.log

Expected behavior The file is reformatted while preserving code structure.

Environment (please complete the following information):

  • Version: Tested against master and 19.3b0
  • OS and Python version: macOS Catalina 10.15.3 Beta / Python 3.7.7

Does this bug also happen on master? Yes. I tested the sample file with https://black.now.sh/?version=master.

@codyd51 codyd51 added the T: bug Something isn't working label Apr 29, 2020
@greschd
Copy link

greschd commented Aug 26, 2020

I've just encountered the same issue, with black==20.8b0, Python 3.7.9, Ubuntu 18.04.

To add some observations, here's another reproducing example:

def foo():
    # yapf: disable
    pass

1

It appears the error is that indentation is wrong after the reformatting: This is the result from black --fast:

def foo():
    # yapf: disable
    pass

    1

@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Sep 27, 2020
@ichard26
Copy link
Collaborator

Duplicate of #569. # yapf: enable/disable are aliases to Black's own # fmt: off/on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R: duplicate This issue or pull request already exists T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants