-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Formatter: Preserve leading empty lines of indented classes and functions #6066
Comments
I'm working on this. |
I've noticed a few other incompatibilities after looking back at my old implementation:
(2) will cause problems with the current approach, I think. As an example, given: x = 1
# comment
def f():
pass Black wants: x = 1
# comment
def f():
pass Whereas we do: x = 1
# comment
def f():
pass That means the code that handles newlines-after-comments needs to now be aware of the thing it's commenting, the level of nesting, etc. |
Perhaps the "easiest" way to get this to work would be to make |
(I will own all of those deviations.) |
Are you looking for input or are these comment's meant as documentation? |
The deviations are just meant as documentation, not expecting any input! Unless you have a quick reaction to the idea I suggested in ‘Perhaps the "easiest" way to get this to work…’, but I haven’t spent time validating that yet. |
I think that could work well. Not sure if implementing custom placement is necessarily easy. |
## Summary This PR ensures that if a function or class is the first statement in a nested suite that _isn't_ a function or class body, we insert a leading newline. For example, given: ```python def f(): if True: def register_type(): pass ``` We _want_ to preserve the newline, whereas today, we remove it. Note that this only applies when the function or class doesn't have any leading comments. Closes #6066.
While the behavior for empty lines before top level classes and functions looks correct, indented classes and function can gain or lose their leading newlines
black:
ours:
The text was updated successfully, but these errors were encountered: