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

Preserve blank line before raw docstrings #3944

Closed
konstin opened this issue Oct 16, 2023 · 1 comment · Fixed by #3947
Closed

Preserve blank line before raw docstrings #3944

konstin opened this issue Oct 16, 2023 · 1 comment · Fixed by #3947
Labels
T: style What do we want Blackened code to look like?

Comments

@konstin
Copy link
Contributor

konstin commented Oct 16, 2023

Describe the style change

Currently, black preserves the blank line before regular doc strings, but not before raw docstrings. It should preserve them before both.

Input

class TextIOWrapper(TextIOBase):
    
    r"""Character and line based layer over a BufferedIOBase object, buffer.

    [...]
    """

    _CHUNK_SIZE = 2048
    
class TextIOWrapper(TextIOBase):
    
    """Character and line based layer over a BufferedIOBase object, buffer.

    [...]
    """

    _CHUNK_SIZE = 2048

Examples in the current Black style

class TextIOWrapper(TextIOBase):
    r"""Character and line based layer over a BufferedIOBase object, buffer.

    [...]
    """

    _CHUNK_SIZE = 2048


class TextIOWrapper(TextIOBase):

    """Character and line based layer over a BufferedIOBase object, buffer.

    [...]
    """

    _CHUNK_SIZE = 2048

Desired style

class TextIOWrapper(TextIOBase):

    r"""Character and line based layer over a BufferedIOBase object, buffer.

    [...]
    """

    _CHUNK_SIZE = 2048


class TextIOWrapper(TextIOBase):

    """Character and line based layer over a BufferedIOBase object, buffer.

    [...]
    """

    _CHUNK_SIZE = 2048

Additional context

Currently, black doesn't seem to consider raw triple quotes strings as docstrings, even though cpython (and PEP 257) do. I've seen some raw triple quoted doc string uses in the wild, such as the above example from cpython.

@konstin konstin added the T: style What do we want Blackened code to look like? label Oct 16, 2023
@JelleZijlstra
Copy link
Collaborator

We should actually remove both blank lines: we do that in #3692 (currently only in the preview style). Agree that we should treat raw strings like docstrings too.

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

Successfully merging a pull request may close this issue.

2 participants