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

[ruff-format] flake8-class-newline #8604

Closed
oysstu opened this issue Nov 10, 2023 · 2 comments
Closed

[ruff-format] flake8-class-newline #8604

oysstu opened this issue Nov 10, 2023 · 2 comments
Labels
formatter Related to the formatter style How should formatted code look

Comments

@oysstu
Copy link

oysstu commented Nov 10, 2023

Working on a codebase where flake8-class-newline is enforced. To quote that module:

PEP8 says we should surround every class method with a single blank line. However flake8 is ambiguous about the first method having a blank line above it.

The ruff formatter currently removes leading spaces after a class definition if there is no docstring. Honestly, I've seen more Python classes without a leading space before the first method than ones with a leading space, so I don't think adding a space should necessary be the default, but it would be nice to have an option for having it (or ignoring it if it exists).

Class without newline (current ruff formatting)

class AClassWithoutANewLine(object):
    def a_method(self):
        return 'a_value'

Class with newline (flake8-class-newline expected formatting)

class AClassWithoutANewLine(object):

    def a_method(self):
        return 'a_value'

When a docstring is present, ruff currently adds a space between the docstring and first method, which passes the flake8-class-newline linter.

@zanieb
Copy link
Member

zanieb commented Nov 10, 2023

Thanks for the report; this is a duplicate of #8566 and I think the reasoning there stands. Happy to hear additional thoughts though.

@zanieb zanieb closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2023
@oysstu
Copy link
Author

oysstu commented Nov 10, 2023

Aha, didn't find that issue when searching. Fair enough, I wish the PEP8 would be more explicit regarding this

@zanieb zanieb added formatter Related to the formatter style How should formatted code look labels Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter style How should formatted code look
Projects
None yet
Development

No branches or pull requests

2 participants