diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/type_params.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/type_params.py index 1cbb4f1549..50aba6ad8e 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/type_params.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/type_params.py @@ -26,3 +26,13 @@ def test [ B, ] (): # fmt: skip ... + +def test [ + # comment + A, + + # another + + B, +] () -> str: # fmt: skip + ... diff --git a/crates/ruff_python_formatter/src/statement/clause.rs b/crates/ruff_python_formatter/src/statement/clause.rs index 465d0921d9..81963ae0ca 100644 --- a/crates/ruff_python_formatter/src/statement/clause.rs +++ b/crates/ruff_python_formatter/src/statement/clause.rs @@ -108,13 +108,17 @@ impl<'a> ClauseHeader<'a> { is_async: _, decorator_list: _, name: _, - returns: _, + returns, body: _, }) => { if let Some(type_params) = type_params.as_ref() { visit(type_params, visitor); } visit(parameters.as_ref(), visitor); + + if let Some(returns) = returns.as_deref() { + visit(returns, visitor); + } } ClauseHeader::If(StmtIf { test, diff --git a/crates/ruff_python_formatter/tests/snapshots/format@fmt_skip__type_params.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@fmt_skip__type_params.py.snap index aa35d9abd8..9bc2f32e01 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@fmt_skip__type_params.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@fmt_skip__type_params.py.snap @@ -32,6 +32,16 @@ def test [ B, ] (): # fmt: skip ... + +def test [ + # comment + A, + + # another + + B, +] () -> str: # fmt: skip + ... ``` ## Output @@ -67,6 +77,17 @@ def test [ B, ] (): # fmt: skip ... + + +def test [ + # comment + A, + + # another + + B, +] () -> str: # fmt: skip + ... ```