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

Empty line and ... and "unindent does not match any outer indentation level" #4291

Closed
Azureblade3808 opened this issue Mar 25, 2024 · 4 comments
Labels
C: crash Black is crashing T: bug Something isn't working

Comments

@Azureblade3808
Copy link

Azureblade3808 commented Mar 25, 2024

Describe the bug

If the first line inside an indented function is empty and the body is ..., black fails to format it.

To Reproduce
https://black.vercel.app/?version=main&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4ACQAFxdAD2IimZxl1N_WlXnON2nzNJyA7rxEz3ITq0Rr8lcyuT-7lJq6-30yBPNldub44lXXOBKYonCShOJuW7cuZ_9TCCgKPjpZqqogwanJNRK0YrZc4gHqvyNL22TtygAACOiGQzKhfHyAAF4kQEAAAC0Mv5wscRn-wIAAAAABFla

class C:
    def f(self):

        ...

Expected behavior

The snippet above can be formatted.

Environment

  • Black's version: Stable: 24.1.0 | Main: @ed770b
  • OS and Python version: irrelevant

Additional context

None.

Edit

Function body being ... is a key condition.

@Azureblade3808 Azureblade3808 added the T: bug Something isn't working label Mar 25, 2024
@Azureblade3808 Azureblade3808 changed the title Empty line and "unindent does not match any outer indentation level" Empty line and ... and "unindent does not match any outer indentation level" Mar 25, 2024
@JelleZijlstra JelleZijlstra added the C: crash Black is crashing label Apr 1, 2024
@JelleZijlstra
Copy link
Collaborator

Confirmed:

% black -c '''class C:
    def f(self):

        ...
'''
class C:
    def f(self):

        ...
error: cannot format <string>: unindent does not match any outer indentation level (<tokenize>, line 5)

Black should instead format this as:

class C:
    def f(self): ...

@harvinmumick
Copy link

Hi, my friend, @peterkra25 , and I are two students from the University of Michigan enrolled in a software engineering class (EECS 481), and our final project is to contribute to an open-source Github project. We came across Black and saw this issue, and reached out to @JelleZijlstra regarding this. We're looking into this issue and will try to resolve it over the next few weeks.

@JelleZijlstra
Copy link
Collaborator

One more thought: I haven't looked at the code, but I suspect the changes in #3796 are closely related to this bug, so looking at the code affected by that change will be a good way to start finding the location of the bug.

@hauntsaninja
Copy link
Collaborator

Thank you for resolving this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: crash Black is crashing T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants