Skip to content

Proposal: strip empty lines between module docstring and first import #3900

@euan-reid

Description

@euan-reid

Describe the style change

Currently Black has no opinion on the number of empty lines that may exist between the module's docstring and the first import line other than collapsing down to at-most-2. I'm proposing that Black should have an opinion, specifically that there should be none (in line with the general philosophy on empty lines).

Examples in the current Black style

All three examples are left unchanged by Black 23.9.1:

"""My super cool module"""


from __future__ import annotations


def foo():
    pass
"""My super cool module"""

from __future__ import annotations


def foo():
    pass
"""My super cool module"""
from __future__ import annotations


def foo():
    pass

Desired style

"""My super cool module"
from __future__ import annotations

def foo():
    pass

Additional context

If there are no imports then Black currently enforces exactly two empty lines between the module docstring and the first line of code. If there's no docstring then Black strips all leading whitespace. I could see an argument that it should be two empty lines between the module docstring and the first import to match the former behaviour, but I think no lines fits better with the general philosophy of the Black style.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: styleWhat do we want Blackened code to look like?

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions