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

Standardise newlines after module-level docstrings #2996

Closed
wants to merge 13 commits into from

Conversation

jpy-git
Copy link
Contributor

@jpy-git jpy-git commented Apr 5, 2022

Description

Closes #1872.

Does 2 things:
a) Refactor EmptyLineTracker for more consistent look-back logic. Simplifies logic by removing complex interactions between before and after for various rules.

b) Standardise newlines after module-level docstrings. We now enforce 1 newline after both single and multi line docstrings.
e.g.

"""docstring"""

import foo
"""docstring

blah blah blah
"""

import foo

Checklist - did you ...

  • Add a CHANGELOG entry if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

@github-actions
Copy link

github-actions bot commented Apr 5, 2022

diff-shades results comparing this PR (c8275d0) to main (c940f75). The full diff is available in the logs under the "Generate HTML diff report" step.

╭──────────────────────── Summary ─────────────────────────╮
│ 14 projects & 572 files changed / 571 changes [+554/-17] │
│                                                          │
│ ... out of 2 206 193 lines, 10 579 files & 23 projects   │
╰──────────────────────────────────────────────────────────╯

Differences found.

What is this? | Workflow run | diff-shades documentation

src/black/lines.py Outdated Show resolved Hide resolved
@JelleZijlstra
Copy link
Collaborator

The number of changes seem surprisingly small. Only a few hundred out of 10k files have a multi-line docstring?

@jpy-git
Copy link
Contributor Author

jpy-git commented Apr 6, 2022

No, it makes sense based on the module docstrings that diff-shades checks:

Total counts:
no_docstring:  10151
single_line_docstring:  183
multi_line_docstring:  721

Copy link
Collaborator

@felix-hilden felix-hilden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, huge thanks for taking on all these issues!

I think I'd prefer the newlines to be added to multiline docstrings as well, just for consistency. Not strongly though, and against my own habits and what I said in the original issue I know, but still.

About the preview handling: certainly this is a feature we'd carry over without question, so no biggie, but having the clarity of being able to search for usages of a potential Preview.docstring_newlines (or similar) was intended to help in picking individual changes for stable. Not that it's likely that we have other changes in EmptyLineTracker so it would be fairly easy to find this one thing, but anyways. Example PR: #2916

I'm trying to slowly get into the processing code. Your modifications seem sensible, but I'm not the authority on that I'm afraid 😄 I do trust the tests though, nice work!

@jpy-git
Copy link
Contributor Author

jpy-git commented Apr 12, 2022

About the preview handling: certainly this is a feature we'd carry over without question, so no biggie, but having the clarity of being able to search for usages of a potential Preview.docstring_newlines (or similar) was intended to help in picking individual changes for stable.

Good point, will update to reference the specific preview mode 😄

I think I'd prefer the newlines to be added to multiline docstrings as well, just for consistency.

Sounds good 👍

Copy link
Collaborator

@felix-hilden felix-hilden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better, and a nice simplification! Again, provided that other maintainers also agree with the style, and that the implementation itself is sound.

CHANGES.md Outdated Show resolved Hide resolved
jpy-git and others added 2 commits May 3, 2022 10:25
Co-authored-by: Felix Hildén <felix.hilden@gmail.com>
Copy link
Collaborator

@ichard26 ichard26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation-wise this is good to go1 (minus all 'em merge conflicts >.<), but I need to catch up all of the discussion around docstrings and newlines (and probably quote placement too) before approving the PR as a whole.

Also, once we settle on a style, could we put it in the future code style documentation? I know this is minor, but as we're trying to keep Black relatively stable, we should be explicit when we do change the style.

Footnotes

  1. I love the refactor, it makes EmptyLineTracker so much nicer to follow :)

@ichard26 ichard26 added this to the Release 22.9.0 milestone Aug 29, 2022
@ichard26 ichard26 added the F: empty lines Wasting vertical space efficiently. label Aug 29, 2022
@ichard26 ichard26 self-assigned this Aug 29, 2022
@ichard26 ichard26 removed this from the Release 22.9.0 milestone Sep 29, 2022
@JelleZijlstra
Copy link
Collaborator

Unfortunately this has a lot of merge conflicts, sorry for dropping the ball here.

@aqeelat
Copy link

aqeelat commented Jun 29, 2023

@JelleZijlstra does it mean that you need help rebasing it?

@JelleZijlstra
Copy link
Collaborator

Yes, somebody will have to rebase this.

@DanielNoord
Copy link
Contributor

@JelleZijlstra I can't rebase on this PR but I'd be happy to invest the time to get this finished. Are you okay with me rebasing this and opening a new PR? (Or somebody else for that matter)

@DanielNoord
Copy link
Contributor

Went ahead and created #3932, please consider reviewing it. Very much open to feedback on how to change the code to make the PR mergeable!

@JelleZijlstra
Copy link
Collaborator

Merged #3932, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: empty lines Wasting vertical space efficiently.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enforce blank line after module docstring
6 participants