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

Latest version of ruff (0.4.2) removes blank double blank line that was allowed previously #11254

Open
taranlu-houzz opened this issue May 2, 2024 · 3 comments
Labels
bug Something isn't working formatter Related to the formatter

Comments

@taranlu-houzz
Copy link

taranlu-houzz commented May 2, 2024

ruff --version: 0.4.2

I recently updated to the latest version of ruff and noticed that in specific cases, a double blank line is now getting changed to a single blank line. I strongly prefer to use double blank lines to visually separate some sections of code, and this only seems to happen in one specific scenario so it is kind of driving me crazy. Here is a code snippet that triggers the change:

#!/usr/bin/env python
# -*- coding: utf-8 -*-


"""Run CLI if package is run directly as a module."""


####################################################################################################
# Imports
####################################################################################################


# ==Package==
from ._private import cli_test_utils


####################################################################################################
# Main
####################################################################################################


cli_test_utils.run_app()

When this is formatted using ruff format <file> (no other flags needed), it remove the blank line above # ==Package==, but leaves all other double blank lines:

#!/usr/bin/env python
# -*- coding: utf-8 -*-


"""Run CLI if package is run directly as a module."""


####################################################################################################
# Imports
####################################################################################################

# ==Package==
from ._private import cli_test_utils


####################################################################################################
# Main
####################################################################################################


cli_test_utils.run_app()

In the past, it did not do this. I'm not sure what the previous working version is, but I may try a few previous versions to see if I can narrow it down.

Update: The last version where it didn't delete the blank line was v0.2.2. The next version, v0.3.0 exhibits the new behavior.

@zanieb
Copy link
Member

zanieb commented May 3, 2024

Hi! It sounds like this was introduced in our stable style mentioned in the v0.3.0 changelog. You can see more details about the stable style at #8678

However, it looks like this is not a part of Black's stable style e.g. I tested with black==24.4.2 and this line is not removed. I wonder if our behavior is intentional.

cc @MichaReiser

@zanieb zanieb added the formatter Related to the formatter label May 3, 2024
@MichaReiser
Copy link
Member

MichaReiser commented May 3, 2024

Yeah, I consider this a bug. The two blank lines should be preserved. I checked out v0.2.2 and narrowed it down that this is due to the preview changes in https://github.com/astral-sh/ruff/pull/8283/files. Although I'm not sure what's the cause.

@MichaReiser MichaReiser added the bug Something isn't working label May 3, 2024
@MichaReiser
Copy link
Member

Hehe, okay, this one is kind of funny, and it's less clear what the intended behavior is. Looking at Black's tests, they are fairly explicit that there should always only be one blank line after a module-level docstring, but that's not what we're seeing in case there's a comment after a module-level docstring.

However, that would only mean that there are two bugs:

  • It should only preserve one blank line between the module docstring and the comment
  • It should preserve two blank lines between the import section and the import comment.

Note: We should not preserve two blank lines in stub files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatter Related to the formatter
Projects
None yet
Development

No branches or pull requests

3 participants