diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/newlines.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/newlines.py index 17806e86d4d791..fd51ac7e4f2222 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/newlines.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/newlines.py @@ -1,6 +1,7 @@ ### # Blank lines around functions ### +import sys x = 1 @@ -209,6 +210,29 @@ def inner(): pass print("below nested functions") + +class Path: + if sys.version_info >= (3, 11): + def joinpath(self): ... + + # The .open method comes from pathlib.pyi and should be kept in sync. + @overload + def open(self): ... + + + + +def fakehttp(): + + class FakeHTTPConnection: + if mock_close: + def close(self): + pass + FakeHTTPConnection.fakedata = fakedata + + + + if True: def nested_trailing_function(): pass \ No newline at end of file diff --git a/crates/ruff_python_formatter/src/statement/suite.rs b/crates/ruff_python_formatter/src/statement/suite.rs index 4b6a2eb6cbd0cd..91c2821826759f 100644 --- a/crates/ruff_python_formatter/src/statement/suite.rs +++ b/crates/ruff_python_formatter/src/statement/suite.rs @@ -376,7 +376,8 @@ impl FormatRule> for FormatSuite { .map(|token| token.kind); if !matches!( next_token_kind, - None | Some(SimpleTokenKind::Def | SimpleTokenKind::Class) + // At is for decorators + None | Some(SimpleTokenKind::Def | SimpleTokenKind::Class | SimpleTokenKind::At) ) { empty_line().fmt(f)?; } diff --git a/crates/ruff_python_formatter/tests/snapshots/format@newlines.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@newlines.py.snap index b4b7bd4b1ed193..cbe9a06bde014e 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@newlines.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@newlines.py.snap @@ -7,6 +7,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/newlines.p ### # Blank lines around functions ### +import sys x = 1 @@ -215,6 +216,16 @@ def outer(): pass print("below nested functions") + +class Path: + if sys.version_info >= (3, 11): + def joinpath(self): ... + + # The .open method comes from pathlib.pyi and should be kept in sync. + @overload + def open(self): ... + + if True: def nested_trailing_function(): pass``` @@ -224,6 +235,7 @@ if True: ### # Blank lines around functions ### +import sys x = 1 @@ -454,6 +466,19 @@ def outer(): print("below nested functions") + +class Path: + if sys.version_info >= (3, 11): + + def joinpath(self): + ... + + # The .open method comes from pathlib.pyi and should be kept in sync. + @overload + def open(self): + ... + + if True: def nested_trailing_function():