You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ._privateimportcli_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 ._privateimportcli_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.
The text was updated successfully, but these errors were encountered:
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.
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.
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
ruff --version
: 0.4.2I 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: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: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.
The text was updated successfully, but these errors were encountered: