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

Black folds ellipsis (...) symbol like class test: ..., which causes flake8 to raise E701 error. #4213

Closed
cainmagi opened this issue Feb 5, 2024 · 5 comments
Labels
T: style What do we want Blackened code to look like?

Comments

@cainmagi
Copy link

cainmagi commented Feb 5, 2024

The issue

The newest black folds the ellipsis (...) to the previous line. This change may violate flake8 E701 rule if ellipsis is used for defining a class.

To Reproduce the issue

The following codes will not raise flake8 errors:

def test():
    ...


class test2:
    ...

After running black, the results are

def test(): ...


class test2: ...  # E701: Multiple statements on one line (colon)

Note that the function test will not raise E701, however the class definition will.

This issue may be caused by a bug of flake8. But I am not sure whether black is the one that should be changed because I remember that the previous version of black will not fold the ... to the previous line.

Additional context

  • black version: 24.1.1
  • flake8 version: 7.0.0 (mccabe: 0.7.0, pycodestyle: 2.11.1, pyflakes: 3.2.0)
  • python version: 3.9.0
@cainmagi cainmagi added the T: style What do we want Blackened code to look like? label Feb 5, 2024
@cainmagi cainmagi changed the title Black folds ellipsis (...) symbol like class test: ... causes flake8 to raise E701 error. Black folds ellipsis (...) symbol like class test: ..., which causes flake8 to raise E701 error. Feb 5, 2024
@cainmagi
Copy link
Author

cainmagi commented Feb 5, 2024

This issue may be related to this one:

PyCQA/pycodestyle#231

The problem is that pycodestyle has not supported the one-liner for classes yet. It looks problematic for me to let black prefer the one-liner style. It looks more reasonable for me if the ... is put on a new line, which will not raise any errors.

@dankrzeminski32
Copy link
Contributor

Duplicate of #4173

@cainmagi
Copy link
Author

cainmagi commented Feb 5, 2024

@dankrzeminski32 Thank you for finding this! Since it duplicates, should I close this issue now?

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Feb 5, 2024
@JelleZijlstra
Copy link
Collaborator

The recommendation is to turn off this lint rule. Personally I'd recommend turning off any formatting-related rules from your linter; if you choose to use Black, formatting is Black's job, not your linter's.

@dankrzeminski32
Copy link
Contributor

@cainmagi I believe so, feel free to consult the updated docs related to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

3 participants