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

One space between class definition and the first inner method #3490

Closed
Danipulok opened this issue Jan 10, 2023 · 3 comments
Closed

One space between class definition and the first inner method #3490

Danipulok opened this issue Jan 10, 2023 · 3 comments
Labels
T: style What do we want Blackened code to look like?

Comments

@Danipulok
Copy link

Always have a blank line between class declaration and first inner method.

How I would like the code to look after black formatting:

class BaseAPIClient:

    def __init__(
        self,
        session: ClientSession,
    ) -> None:
        self._session = session

Code after black current formatting:

class BaseAPIClient:
    def __init__(
        self,
        session: ClientSession,
    ) -> None:
        self._session = session

PEP8
I also refer you to PEP8 blank lines conventions, where the following is mentioned:
Method definitions inside a class are surrounded by a single blank line.

Having this in mind, I'm pretty sure you should rethink not having a single blank line when class doc string is not present.

Screenshot examples
With blank line: https://telegra.ph/file/04d880862ac743cb9fe3b.png
Without blank line: https://telegra.ph/file/0a603992a333412b0fa81.png
IMO, first option is much cleaner + easier to read when you have a lot of methods + follow PEP8.

I think this should be enough to at least think once more about having one blank line after class definition.

Additional context
This is a duplicated issue from Issue #619.

@Danipulok Danipulok added the T: style What do we want Blackened code to look like? label Jan 10, 2023
@JelleZijlstra
Copy link
Collaborator

This was already discussed in #619 and I don't see any reason to change our decision.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Jan 11, 2023
@Danipulok
Copy link
Author

@JelleZijlstra

On black main page, you mention:
Black is a PEP 8 compliant opinionated formatter with its own style.

And at the second page you mention:
The coding style used by Black can be viewed as a strict subset of PEP 8.

I am sure you mention following PEP8 guidance multiple more times at the docs.

If Black's coding style can be viewed as a strict subset of PEP 8, then why does it contradict PEP8 standards?
Quote: Method definitions inside a class are surrounded by a single blank line.

If you don't think this change is required, why not change the docs to make them more truthy and don't pretend black completely follows PEP and can be viewed as a strict subset of PEP 8?

@felix-hilden
Copy link
Collaborator

For what it's worth, to me the rationale is similar to not having blank lines before the first line of a file if it's a def or class, even though PEP 8 says to "surround defs and classes with two blank lines".

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