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

Add newline after module docstrings (module_docstring_newlines) #7995

Closed
Tracked by #6935 ...
DanielNoord opened this issue Oct 16, 2023 · 5 comments · Fixed by #8283
Closed
Tracked by #6935 ...

Add newline after module docstrings (module_docstring_newlines) #7995

DanielNoord opened this issue Oct 16, 2023 · 5 comments · Fixed by #8283
Assignees
Labels
formatter Related to the formatter preview Related to preview mode features

Comments

@DanielNoord
Copy link
Contributor

DanielNoord commented Oct 16, 2023

"""Test docstring"""
a = 1

On the playground this does not currently get a newline added with the format option turned on.

Recently a PR of mine got merged to black to include a newline after the module docstring:
psf/black#3932
Most credits should go to others though for that PR as I mostly copied and rebased code.

It's still in the preview style but got generally favourable responses when initially proposed a couple of year ago. Since nobody has really objected to it during its previous iterations I expect it to be part of the default style some day.

Would ruff be open to to include this change to ruff format as well?

EDIT: Oh, and congrats on the 0.1.0 release 🎉

@charliermarsh
Copy link
Member

Cool, so this is part of Black's preview style? If so, we'll likely add it under our own --preview flag soon.

(And thank you!)

@charliermarsh charliermarsh added the formatter Related to the formatter label Oct 16, 2023
@charliermarsh charliermarsh added this to the Formatter: Stable milestone Oct 16, 2023
@charliermarsh
Copy link
Member

@konstin - Perhaps another good / easy one for preview.

@MichaReiser MichaReiser added the preview Related to preview mode features label Oct 17, 2023
@DanielNoord
Copy link
Contributor Author

@charliermarsh Sorry should have been clearer. This is currently only available on black main as preview. (I run from master locally). You can see in the linked PR that it actually already applies to blacks own codebase. There hasn't been a release yet, I can ask them when they plan on doing so but I don't want to bother the maintainers too much.

@konstin
Copy link
Member

konstin commented Oct 18, 2023

I added a test case in #8044, it's not trivial to fix though

@MichaReiser
Copy link
Member

I added a test case in #8044, it's not trivial to fix though

We could try to format it as part of the module if the first statement in the suite is a doc comment without any leading comments? Not sure how to handle trailing suppression comments though.

@konstin konstin self-assigned this Oct 20, 2023
konstin added a commit that referenced this issue Oct 27, 2023
Change
```python
"""Test docstring"""
a = 1
```
to
```python
"""Test docstring"""

a = 1
```
in preview style, but don't touch the docstring otherwise.

Do we want to ask black to also format the content of module level docstrings? Seems inconsistent to me that we change function and class docstring indentation/contents but not module docstrings.

Fixes #7995
charliermarsh pushed a commit that referenced this issue Oct 28, 2023
Change
```python
"""Test docstring"""
a = 1
```
to
```python
"""Test docstring"""

a = 1
```
in preview style, but don't touch the docstring otherwise.

Do we want to ask black to also format the content of module level
docstrings? Seems inconsistent to me that we change function and class
docstring indentation/contents but not module docstrings.

Fixes #7995
@MichaReiser MichaReiser changed the title Add newline after module docstrings Add newline after module docstrings (module_docstring_newlines) Nov 29, 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 preview Related to preview mode features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants