diff --git a/crates/ruff_python_formatter/src/expression/expr_attribute.rs b/crates/ruff_python_formatter/src/expression/expr_attribute.rs index 31ca2c9a32a6a4..9732025e3563bb 100644 --- a/crates/ruff_python_formatter/src/expression/expr_attribute.rs +++ b/crates/ruff_python_formatter/src/expression/expr_attribute.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -39,7 +40,12 @@ impl FormatNodeRule for FormatExprAttribute { } impl NeedsParentheses for ExprAttribute { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_await.rs b/crates/ruff_python_formatter/src/expression/expr_await.rs index 068677ba1fb018..19c6bf5196a5e4 100644 --- a/crates/ruff_python_formatter/src/expression/expr_await.rs +++ b/crates/ruff_python_formatter/src/expression/expr_await.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -17,7 +18,12 @@ impl FormatNodeRule for FormatExprAwait { } impl NeedsParentheses for ExprAwait { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_bin_op.rs b/crates/ruff_python_formatter/src/expression/expr_bin_op.rs index 7499b4e4f730e0..1016895c2a220f 100644 --- a/crates/ruff_python_formatter/src/expression/expr_bin_op.rs +++ b/crates/ruff_python_formatter/src/expression/expr_bin_op.rs @@ -1,4 +1,4 @@ -use crate::comments::trailing_comments; +use crate::comments::{trailing_comments, Comments}; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parenthesize, }; @@ -171,8 +171,13 @@ impl FormatRule> for FormatOperator { } impl NeedsParentheses for ExprBinOp { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - match default_expression_needs_parentheses(self.into(), parenthesize, source) { + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) { Parentheses::Optional => { if should_binary_break_right_side_first(self) { Parentheses::Custom diff --git a/crates/ruff_python_formatter/src/expression/expr_bool_op.rs b/crates/ruff_python_formatter/src/expression/expr_bool_op.rs index 41ebc548965d02..e97594902900c2 100644 --- a/crates/ruff_python_formatter/src/expression/expr_bool_op.rs +++ b/crates/ruff_python_formatter/src/expression/expr_bool_op.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -20,7 +21,12 @@ impl FormatNodeRule for FormatExprBoolOp { } impl NeedsParentheses for ExprBoolOp { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_call.rs b/crates/ruff_python_formatter/src/expression/expr_call.rs index 4338619cc8e1ec..3f73b6cbbdac87 100644 --- a/crates/ruff_python_formatter/src/expression/expr_call.rs +++ b/crates/ruff_python_formatter/src/expression/expr_call.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -18,8 +19,13 @@ impl FormatNodeRule for FormatExprCall { } impl NeedsParentheses for ExprCall { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - match default_expression_needs_parentheses(self.into(), parenthesize, source) { + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) { Parentheses::Optional => Parentheses::Never, parentheses => parentheses, } diff --git a/crates/ruff_python_formatter/src/expression/expr_compare.rs b/crates/ruff_python_formatter/src/expression/expr_compare.rs index 428f3ed1ce231b..54c5301e851010 100644 --- a/crates/ruff_python_formatter/src/expression/expr_compare.rs +++ b/crates/ruff_python_formatter/src/expression/expr_compare.rs @@ -3,6 +3,7 @@ use crate::expression::parentheses::{ }; use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter}; +use crate::comments::Comments; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprCompare; @@ -21,7 +22,12 @@ impl FormatNodeRule for FormatExprCompare { } impl NeedsParentheses for ExprCompare { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_constant.rs b/crates/ruff_python_formatter/src/expression/expr_constant.rs index 0fc70fa9964bb7..90ee45c1cf731a 100644 --- a/crates/ruff_python_formatter/src/expression/expr_constant.rs +++ b/crates/ruff_python_formatter/src/expression/expr_constant.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -41,8 +42,13 @@ impl FormatNodeRule for FormatExprConstant { } impl NeedsParentheses for ExprConstant { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - match default_expression_needs_parentheses(self.into(), parenthesize, source) { + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) { Parentheses::Optional => Parentheses::Never, parentheses => parentheses, } diff --git a/crates/ruff_python_formatter/src/expression/expr_dict.rs b/crates/ruff_python_formatter/src/expression/expr_dict.rs index 6f173b26ab7f9a..600841f2da0603 100644 --- a/crates/ruff_python_formatter/src/expression/expr_dict.rs +++ b/crates/ruff_python_formatter/src/expression/expr_dict.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -20,8 +21,13 @@ impl FormatNodeRule for FormatExprDict { } impl NeedsParentheses for ExprDict { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - match default_expression_needs_parentheses(self.into(), parenthesize, source) { + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) { Parentheses::Optional => Parentheses::Never, parentheses => parentheses, } diff --git a/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs b/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs index 6a3337f573e39b..4121acb76afc24 100644 --- a/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -20,8 +21,13 @@ impl FormatNodeRule for FormatExprDictComp { } impl NeedsParentheses for ExprDictComp { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - match default_expression_needs_parentheses(self.into(), parenthesize, source) { + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) { Parentheses::Optional => Parentheses::Never, parentheses => parentheses, } diff --git a/crates/ruff_python_formatter/src/expression/expr_formatted_value.rs b/crates/ruff_python_formatter/src/expression/expr_formatted_value.rs index 9578106113eb02..ef2551de321533 100644 --- a/crates/ruff_python_formatter/src/expression/expr_formatted_value.rs +++ b/crates/ruff_python_formatter/src/expression/expr_formatted_value.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -15,7 +16,12 @@ impl FormatNodeRule for FormatExprFormattedValue { } impl NeedsParentheses for ExprFormattedValue { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs b/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs index 2cf35598eabe7a..54762794e33711 100644 --- a/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -15,8 +16,13 @@ impl FormatNodeRule for FormatExprGeneratorExp { } impl NeedsParentheses for ExprGeneratorExp { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - match default_expression_needs_parentheses(self.into(), parenthesize, source) { + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) { Parentheses::Optional => Parentheses::Never, parentheses => parentheses, } diff --git a/crates/ruff_python_formatter/src/expression/expr_if_exp.rs b/crates/ruff_python_formatter/src/expression/expr_if_exp.rs index e60ebbf8f0a739..980571d853f0ab 100644 --- a/crates/ruff_python_formatter/src/expression/expr_if_exp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_if_exp.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -20,7 +21,12 @@ impl FormatNodeRule for FormatExprIfExp { } impl NeedsParentheses for ExprIfExp { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_joined_str.rs b/crates/ruff_python_formatter/src/expression/expr_joined_str.rs index 86194c9b2b3088..a13ff5f38971d8 100644 --- a/crates/ruff_python_formatter/src/expression/expr_joined_str.rs +++ b/crates/ruff_python_formatter/src/expression/expr_joined_str.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -15,7 +16,12 @@ impl FormatNodeRule for FormatExprJoinedStr { } impl NeedsParentheses for ExprJoinedStr { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_lambda.rs b/crates/ruff_python_formatter/src/expression/expr_lambda.rs index c1310de391f539..bd63bfa0f63b9a 100644 --- a/crates/ruff_python_formatter/src/expression/expr_lambda.rs +++ b/crates/ruff_python_formatter/src/expression/expr_lambda.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -15,7 +16,12 @@ impl FormatNodeRule for FormatExprLambda { } impl NeedsParentheses for ExprLambda { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_list.rs b/crates/ruff_python_formatter/src/expression/expr_list.rs index 869542621e7cf0..20153d8aa78685 100644 --- a/crates/ruff_python_formatter/src/expression/expr_list.rs +++ b/crates/ruff_python_formatter/src/expression/expr_list.rs @@ -1,4 +1,4 @@ -use crate::comments::dangling_comments; +use crate::comments::{dangling_comments, Comments}; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -57,8 +57,13 @@ impl FormatNodeRule for FormatExprList { } impl NeedsParentheses for ExprList { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - match default_expression_needs_parentheses(self.into(), parenthesize, source) { + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) { Parentheses::Optional => Parentheses::Never, parentheses => parentheses, } diff --git a/crates/ruff_python_formatter/src/expression/expr_list_comp.rs b/crates/ruff_python_formatter/src/expression/expr_list_comp.rs index 8fddfa5457849f..3ab6a61f06e00e 100644 --- a/crates/ruff_python_formatter/src/expression/expr_list_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_list_comp.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -15,8 +16,13 @@ impl FormatNodeRule for FormatExprListComp { } impl NeedsParentheses for ExprListComp { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - match default_expression_needs_parentheses(self.into(), parenthesize, source) { + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) { Parentheses::Optional => Parentheses::Never, parentheses => parentheses, } diff --git a/crates/ruff_python_formatter/src/expression/expr_name.rs b/crates/ruff_python_formatter/src/expression/expr_name.rs index 57ad099c38c78f..25673494818c8e 100644 --- a/crates/ruff_python_formatter/src/expression/expr_name.rs +++ b/crates/ruff_python_formatter/src/expression/expr_name.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -26,8 +27,13 @@ impl FormatNodeRule for FormatExprName { } impl NeedsParentheses for ExprName { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_named_expr.rs b/crates/ruff_python_formatter/src/expression/expr_named_expr.rs index 4cf013217d0cc3..71d2bae8910532 100644 --- a/crates/ruff_python_formatter/src/expression/expr_named_expr.rs +++ b/crates/ruff_python_formatter/src/expression/expr_named_expr.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -15,7 +16,12 @@ impl FormatNodeRule for FormatExprNamedExpr { } impl NeedsParentheses for ExprNamedExpr { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_set.rs b/crates/ruff_python_formatter/src/expression/expr_set.rs index e3bf2d8a504764..7e379d1cea4b28 100644 --- a/crates/ruff_python_formatter/src/expression/expr_set.rs +++ b/crates/ruff_python_formatter/src/expression/expr_set.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -34,8 +35,13 @@ impl FormatNodeRule for FormatExprSet { } impl NeedsParentheses for ExprSet { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - match default_expression_needs_parentheses(self.into(), parenthesize, source) { + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) { Parentheses::Optional => Parentheses::Never, parentheses => parentheses, } diff --git a/crates/ruff_python_formatter/src/expression/expr_set_comp.rs b/crates/ruff_python_formatter/src/expression/expr_set_comp.rs index df3405a2c9d1ed..a73ede1c68c174 100644 --- a/crates/ruff_python_formatter/src/expression/expr_set_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_set_comp.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -15,8 +16,13 @@ impl FormatNodeRule for FormatExprSetComp { } impl NeedsParentheses for ExprSetComp { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - match default_expression_needs_parentheses(self.into(), parenthesize, source) { + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) { Parentheses::Optional => Parentheses::Never, parentheses => parentheses, } diff --git a/crates/ruff_python_formatter/src/expression/expr_slice.rs b/crates/ruff_python_formatter/src/expression/expr_slice.rs index 35b559f285ccf0..529ef4679ba82b 100644 --- a/crates/ruff_python_formatter/src/expression/expr_slice.rs +++ b/crates/ruff_python_formatter/src/expression/expr_slice.rs @@ -3,6 +3,7 @@ use crate::expression::parentheses::{ }; use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter}; +use crate::comments::Comments; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprSlice; @@ -21,7 +22,12 @@ impl FormatNodeRule for FormatExprSlice { } impl NeedsParentheses for ExprSlice { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_starred.rs b/crates/ruff_python_formatter/src/expression/expr_starred.rs index c06a64aaa3f495..14806cb52b7ad3 100644 --- a/crates/ruff_python_formatter/src/expression/expr_starred.rs +++ b/crates/ruff_python_formatter/src/expression/expr_starred.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -15,7 +16,12 @@ impl FormatNodeRule for FormatExprStarred { } impl NeedsParentheses for ExprStarred { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_subscript.rs b/crates/ruff_python_formatter/src/expression/expr_subscript.rs index 559f747292d1a5..6874b1415a6838 100644 --- a/crates/ruff_python_formatter/src/expression/expr_subscript.rs +++ b/crates/ruff_python_formatter/src/expression/expr_subscript.rs @@ -3,6 +3,7 @@ use crate::expression::parentheses::{ }; use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter}; +use crate::comments::Comments; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprSubscript; @@ -21,7 +22,12 @@ impl FormatNodeRule for FormatExprSubscript { } impl NeedsParentheses for ExprSubscript { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_tuple.rs b/crates/ruff_python_formatter/src/expression/expr_tuple.rs index cc83eb33182c3e..ba96180a15ebc0 100644 --- a/crates/ruff_python_formatter/src/expression/expr_tuple.rs +++ b/crates/ruff_python_formatter/src/expression/expr_tuple.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -15,8 +16,13 @@ impl FormatNodeRule for FormatExprTuple { } impl NeedsParentheses for ExprTuple { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - match default_expression_needs_parentheses(self.into(), parenthesize, source) { + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) { Parentheses::Optional => Parentheses::Never, parentheses => parentheses, } diff --git a/crates/ruff_python_formatter/src/expression/expr_unary_op.rs b/crates/ruff_python_formatter/src/expression/expr_unary_op.rs index 8df9831255e35a..9f91d13e4022d6 100644 --- a/crates/ruff_python_formatter/src/expression/expr_unary_op.rs +++ b/crates/ruff_python_formatter/src/expression/expr_unary_op.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -15,7 +16,12 @@ impl FormatNodeRule for FormatExprUnaryOp { } impl NeedsParentheses for ExprUnaryOp { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_yield.rs b/crates/ruff_python_formatter/src/expression/expr_yield.rs index 7e9f27f5da42d6..f2ece7ecac66e5 100644 --- a/crates/ruff_python_formatter/src/expression/expr_yield.rs +++ b/crates/ruff_python_formatter/src/expression/expr_yield.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -15,7 +16,12 @@ impl FormatNodeRule for FormatExprYield { } impl NeedsParentheses for ExprYield { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_yield_from.rs b/crates/ruff_python_formatter/src/expression/expr_yield_from.rs index 5ed9bd63546675..bfaf10116221cd 100644 --- a/crates/ruff_python_formatter/src/expression/expr_yield_from.rs +++ b/crates/ruff_python_formatter/src/expression/expr_yield_from.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -15,7 +16,12 @@ impl FormatNodeRule for FormatExprYieldFrom { } impl NeedsParentheses for ExprYieldFrom { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { - default_expression_needs_parentheses(self.into(), parenthesize, source) + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { + default_expression_needs_parentheses(self.into(), parenthesize, source, comments) } } diff --git a/crates/ruff_python_formatter/src/expression/mod.rs b/crates/ruff_python_formatter/src/expression/mod.rs index a8059c8b7489e0..706c59f29f7ba7 100644 --- a/crates/ruff_python_formatter/src/expression/mod.rs +++ b/crates/ruff_python_formatter/src/expression/mod.rs @@ -1,3 +1,4 @@ +use crate::comments::Comments; use crate::context::NodeLevel; use crate::expression::parentheses::{NeedsParentheses, Parentheses, Parenthesize}; use crate::prelude::*; @@ -51,7 +52,11 @@ impl FormatRuleWithOptions> for FormatExpr { impl FormatRule> for FormatExpr { fn fmt(&self, item: &Expr, f: &mut PyFormatter) -> FormatResult<()> { - let parentheses = item.needs_parentheses(self.parenthesize, f.context().contents()); + let parentheses = item.needs_parentheses( + self.parenthesize, + f.context().contents(), + f.context().comments(), + ); let format_expr = format_with(|f| match item { Expr::BoolOp(expr) => expr.format().fmt(f), @@ -118,35 +123,40 @@ impl FormatRule> for FormatExpr { } impl NeedsParentheses for Expr { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses { + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses { match self { - Expr::BoolOp(expr) => expr.needs_parentheses(parenthesize, source), - Expr::NamedExpr(expr) => expr.needs_parentheses(parenthesize, source), - Expr::BinOp(expr) => expr.needs_parentheses(parenthesize, source), - Expr::UnaryOp(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Lambda(expr) => expr.needs_parentheses(parenthesize, source), - Expr::IfExp(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Dict(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Set(expr) => expr.needs_parentheses(parenthesize, source), - Expr::ListComp(expr) => expr.needs_parentheses(parenthesize, source), - Expr::SetComp(expr) => expr.needs_parentheses(parenthesize, source), - Expr::DictComp(expr) => expr.needs_parentheses(parenthesize, source), - Expr::GeneratorExp(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Await(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Yield(expr) => expr.needs_parentheses(parenthesize, source), - Expr::YieldFrom(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Compare(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Call(expr) => expr.needs_parentheses(parenthesize, source), - Expr::FormattedValue(expr) => expr.needs_parentheses(parenthesize, source), - Expr::JoinedStr(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Constant(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Attribute(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Subscript(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Starred(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Name(expr) => expr.needs_parentheses(parenthesize, source), - Expr::List(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Tuple(expr) => expr.needs_parentheses(parenthesize, source), - Expr::Slice(expr) => expr.needs_parentheses(parenthesize, source), + Expr::BoolOp(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::NamedExpr(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::BinOp(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::UnaryOp(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Lambda(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::IfExp(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Dict(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Set(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::ListComp(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::SetComp(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::DictComp(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::GeneratorExp(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Await(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Yield(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::YieldFrom(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Compare(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Call(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::FormattedValue(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::JoinedStr(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Constant(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Attribute(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Subscript(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Starred(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Name(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::List(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Tuple(expr) => expr.needs_parentheses(parenthesize, source, comments), + Expr::Slice(expr) => expr.needs_parentheses(parenthesize, source, comments), } } } diff --git a/crates/ruff_python_formatter/src/expression/parentheses.rs b/crates/ruff_python_formatter/src/expression/parentheses.rs index 06d599ad2ccaec..58d083c8c6f4a7 100644 --- a/crates/ruff_python_formatter/src/expression/parentheses.rs +++ b/crates/ruff_python_formatter/src/expression/parentheses.rs @@ -1,15 +1,22 @@ +use crate::comments::Comments; use crate::trivia::{first_non_trivia_token, first_non_trivia_token_rev, Token, TokenKind}; use ruff_python_ast::node::AnyNodeRef; use rustpython_parser::ast::Ranged; pub(crate) trait NeedsParentheses { - fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses; + fn needs_parentheses( + &self, + parenthesize: Parenthesize, + source: &str, + comments: &Comments, + ) -> Parentheses; } pub(super) fn default_expression_needs_parentheses( node: AnyNodeRef, parenthesize: Parenthesize, source: &str, + comments: &Comments, ) -> Parentheses { debug_assert!( node.is_expression(), @@ -20,9 +27,14 @@ pub(super) fn default_expression_needs_parentheses( if !parenthesize.is_if_breaks() && is_expression_parenthesized(node, source) { Parentheses::Always } - // `Optional` or `IfBreaks`: Add parentheses if the expression doesn't fit on a line + // `Optional` or `IfBreaks`: Add parentheses if the expression doesn't fit on a line but enforce + // parentheses if the expression has leading comments else if !parenthesize.is_preserve() { - Parentheses::Optional + if comments.has_leading_comments(node) { + Parentheses::Always + } else { + Parentheses::Optional + } } else { //`Preserve` and expression has no parentheses in the source code Parentheses::Never diff --git a/crates/ruff_python_formatter/src/lib.rs b/crates/ruff_python_formatter/src/lib.rs index 90dbe79e488113..42fd45ffd5624d 100644 --- a/crates/ruff_python_formatter/src/lib.rs +++ b/crates/ruff_python_formatter/src/lib.rs @@ -231,6 +231,7 @@ mod tests { use anyhow::Result; use insta::assert_snapshot; + use rustpython_parser::lexer::lex; use rustpython_parser::{parse_tokens, Mode}; use similar::TextDiff; diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_blank_parentheses_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_blank_parentheses_py.snap index a3d4aa887b9107..301e65440e73d8 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_blank_parentheses_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_blank_parentheses_py.snap @@ -36,7 +36,7 @@ class NormalClass ( ```diff --- Black +++ Ruff -@@ -1,30 +1,18 @@ +@@ -1,18 +1,10 @@ -class SimpleClassWithBlankParentheses: - pass +NOT_YET_IMPLEMENTED_StmtClassDef @@ -58,8 +58,7 @@ class NormalClass ( def public_func_with_blank_parentheses(): -- return None -+ NOT_YET_IMPLEMENTED_StmtReturn +@@ -20,11 +12,7 @@ def class_under_the_func_with_blank_parentheses(): @@ -88,7 +87,7 @@ NOT_YET_IMPLEMENTED_StmtClassDef def public_func_with_blank_parentheses(): - NOT_YET_IMPLEMENTED_StmtReturn + return None def class_under_the_func_with_blank_parentheses(): diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comment_after_escaped_newline_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comment_after_escaped_newline_py.snap index e41288972fe6ed..92e670eafabb96 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comment_after_escaped_newline_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comment_after_escaped_newline_py.snap @@ -24,17 +24,15 @@ def bobtwo(): \ +++ Ruff @@ -1,6 +1,8 @@ -def bob(): # pylint: disable=W9016 -- pass +def bob(): + # pylint: disable=W9016 -+ NOT_YET_IMPLEMENTED_StmtPass + pass -def bobtwo(): # some comment here -- pass +def bobtwo(): + # some comment here -+ NOT_YET_IMPLEMENTED_StmtPass + pass ``` ## Ruff Output @@ -42,12 +40,12 @@ def bobtwo(): \ ```py def bob(): # pylint: disable=W9016 - NOT_YET_IMPLEMENTED_StmtPass + pass def bobtwo(): # some comment here - NOT_YET_IMPLEMENTED_StmtPass + pass ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments2_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments2_py.snap index 7440c67656af87..44a3cffad7f79f 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments2_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments2_py.snap @@ -351,7 +351,7 @@ instruction()#comment with bad spacing - syms.simple_stmt, - [Node(statement, result), Leaf(token.NEWLINE, "\n")], # FIXME: \r\n? - ) -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return NOT_IMPLEMENTED_call() -CONFIG_FILES = ( @@ -461,7 +461,7 @@ def inline_comments_in_brackets_ruin_everything(): # and round and round we go # let's return - NOT_YET_IMPLEMENTED_StmtReturn + return NOT_IMPLEMENTED_call() CONFIG_FILES = [CONFIG_FILE] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments4_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments4_py.snap index 1d2e9948e86070..9d741d8b926d46 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments4_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments4_py.snap @@ -107,7 +107,7 @@ def foo3(list_a, list_b): ```diff --- Black +++ Ruff -@@ -1,94 +1,19 @@ +@@ -1,94 +1,22 @@ -from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( - MyLovelyCompanyTeamProjectComponent, # NOT DRY -) @@ -182,9 +182,8 @@ def foo3(list_a, list_b): - .with_for_update(key_share=True) - .all() - ) -- return results + results = NOT_IMPLEMENTED_call() -+ NOT_YET_IMPLEMENTED_StmtReturn + return results def foo2(list_a, list_b): @@ -196,19 +195,19 @@ def foo3(list_a, list_b): - ) - .filter(User.xyz.is_(None)) - ) -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return NOT_IMPLEMENTED_call() def foo3(list_a, list_b): -- return ( -- # Standalone comment but weirdly placed. + return ( + # Standalone comment but weirdly placed. - User.query.filter(User.foo == "bar") - .filter( - db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b)) - ) - .filter(User.xyz.is_(None)) -- ) -+ NOT_YET_IMPLEMENTED_StmtReturn ++ NOT_IMPLEMENTED_call() + ) ``` ## Ruff Output @@ -223,16 +222,19 @@ NOT_YET_IMPLEMENTED_StmtClassDef def foo(list_a, list_b): results = NOT_IMPLEMENTED_call() - NOT_YET_IMPLEMENTED_StmtReturn + return results def foo2(list_a, list_b): # Standalone comment reasonably placed. - NOT_YET_IMPLEMENTED_StmtReturn + return NOT_IMPLEMENTED_call() def foo3(list_a, list_b): - NOT_YET_IMPLEMENTED_StmtReturn + return ( + # Standalone comment but weirdly placed. + NOT_IMPLEMENTED_call() + ) ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments6_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments6_py.snap index c6900bb590f3b6..3009fba804bf4f 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments6_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments6_py.snap @@ -131,43 +131,11 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite ```diff --- Black +++ Ruff -@@ -1,16 +1,16 @@ +@@ -1,4 +1,4 @@ -from typing import Any, Tuple +NOT_YET_IMPLEMENTED_StmtImportFrom - def f( - a, # type: int - ): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - - - # test type comments - def f(a, b, c, d, e, f, g, h, i): - # type: (int, int, int, int, int, int, int, int, int) -> None -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - - - def f( -@@ -25,7 +25,7 @@ - i, # type: int - ): - # type: (...) -> None -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - - - def f( -@@ -35,7 +35,7 @@ - **kwargs, # type: **Any - ): - # type: (...) -> None -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - - def f( @@ -49,15 +49,10 @@ element = 0 # type: int @@ -188,19 +156,7 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite a = ( element -@@ -74,45 +69,32 @@ - y, # type: int - ): - # type: (...) -> None -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - - - def f( - x, # not a type comment - ): # type: (int) -> None -- pass -+ NOT_YET_IMPLEMENTED_StmtPass +@@ -84,35 +79,22 @@ def func( @@ -259,13 +215,13 @@ NOT_YET_IMPLEMENTED_StmtImportFrom def f( a, # type: int ): - NOT_YET_IMPLEMENTED_StmtPass + pass # test type comments def f(a, b, c, d, e, f, g, h, i): # type: (int, int, int, int, int, int, int, int, int) -> None - NOT_YET_IMPLEMENTED_StmtPass + pass def f( @@ -280,7 +236,7 @@ def f( i, # type: int ): # type: (...) -> None - NOT_YET_IMPLEMENTED_StmtPass + pass def f( @@ -290,7 +246,7 @@ def f( **kwargs, # type: **Any ): # type: (...) -> None - NOT_YET_IMPLEMENTED_StmtPass + pass def f( @@ -324,13 +280,13 @@ def f( y, # type: int ): # type: (...) -> None - NOT_YET_IMPLEMENTED_StmtPass + pass def f( x, # not a type comment ): # type: (int) -> None - NOT_YET_IMPLEMENTED_StmtPass + pass def func( diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments9_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments9_py.snap index 595408260fe76a..49e1cc324fa03b 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments9_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments9_py.snap @@ -152,33 +152,7 @@ def bar(): ```diff --- Black +++ Ruff -@@ -5,7 +5,7 @@ - - # This comment should be split from the statement above by two lines. - def function(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - - - some = statement -@@ -15,7 +15,7 @@ - # should be split from the statement - # above by two lines. - def function(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - - - some = statement -@@ -23,15 +23,14 @@ - - # This comment should be split from the statement above by two lines. - async def async_function(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - - - some = statement +@@ -30,8 +30,7 @@ # This comment should be split from the statement above by two lines. @@ -209,7 +183,7 @@ def bar(): some = statement -@@ -59,12 +55,12 @@ +@@ -59,7 +55,7 @@ @deco1 # leading 2 # leading 2 extra @@ -218,13 +192,7 @@ def bar(): # leading 3 @deco3 # leading 4 - def decorated(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - - - some = statement -@@ -73,13 +69,13 @@ +@@ -73,7 +69,7 @@ # leading 1 @deco1 # leading 2 @@ -233,14 +201,7 @@ def bar(): # leading 3 that already has an empty line @deco3 - # leading 4 - def decorated_with_split_leading_comments(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - - - some = statement -@@ -88,68 +84,40 @@ +@@ -88,7 +84,7 @@ # leading 1 @deco1 # leading 2 @@ -249,10 +210,7 @@ def bar(): # leading 3 @deco3 - # leading 4 that already has an empty line - def decorated_with_split_leading_comments(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass +@@ -98,41 +94,13 @@ def main(): @@ -271,17 +229,17 @@ def bar(): - def inline_after_else(): - pass -- ++NOT_YET_IMPLEMENTED_StmtIf + -if a: - # Leading comment before "top-level inline" function - def top_level_quote_inline(): - pass -+NOT_YET_IMPLEMENTED_StmtIf - # Another leading comment - def another_top_level_quote_inline_inline(): - pass - +- -else: - # More leading comments - def top_level_quote_inline_after_else(): @@ -297,32 +255,6 @@ def bar(): # Regression test for https://github.com/psf/black/issues/3454. - def foo(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - # Trailing comment that belongs to this function - - - @decorator1 - @decorator2 # fmt: skip - def bar(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - - - # Regression test for https://github.com/psf/black/issues/3454. - def foo(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - # Trailing comment that belongs to this function. - # NOTE this comment only has one empty line below, and the formatter - # should enforce two blank lines. -@@ -158,4 +126,4 @@ - @decorator1 - # A standalone comment - def bar(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass ``` ## Ruff Output @@ -335,7 +267,7 @@ some = statement # This comment should be split from the statement above by two lines. def function(): - NOT_YET_IMPLEMENTED_StmtPass + pass some = statement @@ -345,7 +277,7 @@ some = statement # should be split from the statement # above by two lines. def function(): - NOT_YET_IMPLEMENTED_StmtPass + pass some = statement @@ -353,7 +285,7 @@ some = statement # This comment should be split from the statement above by two lines. async def async_function(): - NOT_YET_IMPLEMENTED_StmtPass + pass some = statement @@ -390,7 +322,7 @@ some = statement @deco3 # leading 4 def decorated(): - NOT_YET_IMPLEMENTED_StmtPass + pass some = statement @@ -405,7 +337,7 @@ some = statement @deco3 # leading 4 def decorated_with_split_leading_comments(): - NOT_YET_IMPLEMENTED_StmtPass + pass some = statement @@ -420,7 +352,7 @@ some = statement # leading 4 that already has an empty line def decorated_with_split_leading_comments(): - NOT_YET_IMPLEMENTED_StmtPass + pass def main(): @@ -435,19 +367,19 @@ NOT_YET_IMPLEMENTED_StmtClassDef # Regression test for https://github.com/psf/black/issues/3454. def foo(): - NOT_YET_IMPLEMENTED_StmtPass + pass # Trailing comment that belongs to this function @decorator1 @decorator2 # fmt: skip def bar(): - NOT_YET_IMPLEMENTED_StmtPass + pass # Regression test for https://github.com/psf/black/issues/3454. def foo(): - NOT_YET_IMPLEMENTED_StmtPass + pass # Trailing comment that belongs to this function. # NOTE this comment only has one empty line below, and the formatter # should enforce two blank lines. @@ -456,7 +388,7 @@ def foo(): @decorator1 # A standalone comment def bar(): - NOT_YET_IMPLEMENTED_StmtPass + pass ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_non_breaking_space_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_non_breaking_space_py.snap index 596011b8918c31..cddc816cdbc83b 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_non_breaking_space_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_non_breaking_space_py.snap @@ -59,8 +59,7 @@ def function(a:int=42): + "NOT_YET_IMPLEMENTED_STRING" # There's a NBSP + 3 spaces before # And 4 spaces on the next line -- pass -+ NOT_YET_IMPLEMENTED_StmtPass + pass ``` ## Ruff Output @@ -80,7 +79,7 @@ def function(a: int = 42): "NOT_YET_IMPLEMENTED_STRING" # There's a NBSP + 3 spaces before # And 4 spaces on the next line - NOT_YET_IMPLEMENTED_StmtPass + pass ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_py.snap index f2f486c0f34d03..594d47fcf3ee78 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_py.snap @@ -114,27 +114,27 @@ async def wat(): # Has many lines. Many, many lines. # Many, many, many lines. -"""Module docstring. -+"NOT_YET_IMPLEMENTED_STRING" - +- -Possibly also many, many lines. -""" -+NOT_YET_IMPLEMENTED_StmtImport -+NOT_YET_IMPLEMENTED_StmtImport ++"NOT_YET_IMPLEMENTED_STRING" -import os.path -import sys -- ++NOT_YET_IMPLEMENTED_StmtImport ++NOT_YET_IMPLEMENTED_StmtImport + -import a -from b.c import X # some noqa comment -- ++NOT_YET_IMPLEMENTED_StmtImport ++NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment + -try: - import fast -except ImportError: - import slow as fast - -+NOT_YET_IMPLEMENTED_StmtImport -+NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment - +- -# Some comment before a function. +NOT_YET_IMPLEMENTED_StmtTry y = 1 @@ -161,8 +161,7 @@ async def wat(): + NOT_YET_IMPLEMENTED_StmtIf # This return is also commented for some reason. -- return default -+ NOT_YET_IMPLEMENTED_StmtReturn + return default # Explains why we use global state. @@ -172,7 +171,7 @@ async def wat(): # Another comment! # This time two lines. - +- -class Foo: - """Docstring for class Foo. Example from Sphinx docs.""" @@ -180,7 +179,7 @@ async def wat(): - #: Doc comment for class attribute Foo.bar. - #: It can have multiple lines. - bar = 1 -- + - flox = 1.5 #: Doc comment for Foo.flox. One line only. - - baz = 2 @@ -254,7 +253,7 @@ def function(default=None): NOT_YET_IMPLEMENTED_StmtIf # This return is also commented for some reason. - NOT_YET_IMPLEMENTED_StmtReturn + return default # Explains why we use global state. diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_py.snap index 176a86165cc810..ca085ed0883cb4 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_py.snap @@ -252,35 +252,31 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self): - """This is a docstring with - some lines of text here - """ -- return + "NOT_YET_IMPLEMENTED_STRING" -+ NOT_YET_IMPLEMENTED_StmtReturn + return def bar(): - """This is another docstring - with more lines of text - """ -- return + "NOT_YET_IMPLEMENTED_STRING" -+ NOT_YET_IMPLEMENTED_StmtReturn + return def baz(): - '''"This" is a string with some - embedded "quotes"''' -- return + "NOT_YET_IMPLEMENTED_STRING" -+ NOT_YET_IMPLEMENTED_StmtReturn + return def troz(): - """Indentation with tabs - is just as OK - """ -- return + "NOT_YET_IMPLEMENTED_STRING" -+ NOT_YET_IMPLEMENTED_StmtReturn + return def zort(): @@ -288,9 +284,8 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self): - multiline - docstring - """ -- pass + "NOT_YET_IMPLEMENTED_STRING" -+ NOT_YET_IMPLEMENTED_StmtPass + pass def poit(): @@ -304,9 +299,8 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self): - - quis nostrud exercitation ullamco laboris nisi - - aliquip ex ea commodo consequat - """ -- pass + "NOT_YET_IMPLEMENTED_STRING" -+ NOT_YET_IMPLEMENTED_StmtPass + pass def under_indent(): @@ -314,9 +308,8 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self): - These lines are indented in a way that does not - make sense. - """ -- pass + "NOT_YET_IMPLEMENTED_STRING" -+ NOT_YET_IMPLEMENTED_StmtPass + pass def over_indent(): @@ -325,16 +318,14 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self): - - But some lines are deeper - - And the closing quote is too deep - """ -- pass + "NOT_YET_IMPLEMENTED_STRING" -+ NOT_YET_IMPLEMENTED_StmtPass + pass def single_line(): - """But with a newline after it!""" -- pass + "NOT_YET_IMPLEMENTED_STRING" -+ NOT_YET_IMPLEMENTED_StmtPass + pass def this(): @@ -421,9 +412,8 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self): - - line ends with some tabs - """ -- pass + "NOT_YET_IMPLEMENTED_STRING" -+ NOT_YET_IMPLEMENTED_StmtPass + pass def backslash_space(): @@ -475,12 +465,12 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self): def docstring_almost_at_line_limit2(): - """long docstring................................................................. -+ "NOT_YET_IMPLEMENTED_STRING" - +- - .................................................................................. - """ ++ "NOT_YET_IMPLEMENTED_STRING" + -- def docstring_at_line_limit(): - """long docstring................................................................""" + "NOT_YET_IMPLEMENTED_STRING" @@ -509,47 +499,47 @@ NOT_YET_IMPLEMENTED_StmtClassDef def foo(): "NOT_YET_IMPLEMENTED_STRING" - NOT_YET_IMPLEMENTED_StmtReturn + return def bar(): "NOT_YET_IMPLEMENTED_STRING" - NOT_YET_IMPLEMENTED_StmtReturn + return def baz(): "NOT_YET_IMPLEMENTED_STRING" - NOT_YET_IMPLEMENTED_StmtReturn + return def troz(): "NOT_YET_IMPLEMENTED_STRING" - NOT_YET_IMPLEMENTED_StmtReturn + return def zort(): "NOT_YET_IMPLEMENTED_STRING" - NOT_YET_IMPLEMENTED_StmtPass + pass def poit(): "NOT_YET_IMPLEMENTED_STRING" - NOT_YET_IMPLEMENTED_StmtPass + pass def under_indent(): "NOT_YET_IMPLEMENTED_STRING" - NOT_YET_IMPLEMENTED_StmtPass + pass def over_indent(): "NOT_YET_IMPLEMENTED_STRING" - NOT_YET_IMPLEMENTED_StmtPass + pass def single_line(): "NOT_YET_IMPLEMENTED_STRING" - NOT_YET_IMPLEMENTED_StmtPass + pass def this(): @@ -602,7 +592,7 @@ def docstring_with_inline_tabs_and_space_indentation(): def docstring_with_inline_tabs_and_tab_indentation(): "NOT_YET_IMPLEMENTED_STRING" - NOT_YET_IMPLEMENTED_StmtPass + pass def backslash_space(): diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff2_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff2_py.snap index a6f3e2491ea1ed..d4de723ff02513 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff2_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff2_py.snap @@ -65,9 +65,9 @@ def test_calculate_fades(): + # Test data: # Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]] -- --@pytest.mark.parametrize('test', [ +-@pytest.mark.parametrize('test', [ +- - # Test don't manage the volume - [ - ('stuff', 'in') @@ -75,22 +75,20 @@ def test_calculate_fades(): -]) +@NOT_IMPLEMENTED_call() def test_fader(test): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass -+ + pass ++ def check_fader(test): -+ NOT_YET_IMPLEMENTED_StmtPass ++ pass - pass def verify_fader(test): - # misaligned comment -- pass + # misaligned comment -+ NOT_YET_IMPLEMENTED_StmtPass -+ + pass ++ def verify_fader(test): - """Hey, ho.""" - assert test.passed() @@ -126,16 +124,16 @@ TmEx = 2 @NOT_IMPLEMENTED_call() def test_fader(test): - NOT_YET_IMPLEMENTED_StmtPass + pass def check_fader(test): - NOT_YET_IMPLEMENTED_StmtPass + pass def verify_fader(test): # misaligned comment - NOT_YET_IMPLEMENTED_StmtPass + pass def verify_fader(test): diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff4_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff4_py.snap index 0ba9673debd89b..9fd0b0b4b4dc39 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff4_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff4_py.snap @@ -35,8 +35,7 @@ def f(): pass +@NOT_IMPLEMENTED_call() # fmt: on def f(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass + pass -@test( @@ -49,8 +48,7 @@ def f(): pass -) +@NOT_IMPLEMENTED_call() def f(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass + pass ``` ## Ruff Output @@ -60,12 +58,12 @@ def f(): pass @NOT_IMPLEMENTED_call() # fmt: on def f(): - NOT_YET_IMPLEMENTED_StmtPass + pass @NOT_IMPLEMENTED_call() def f(): - NOT_YET_IMPLEMENTED_StmtPass + pass ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff5_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff5_py.snap index 14699e3cb2bf93..ec7df09c267618 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff5_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff5_py.snap @@ -136,8 +136,7 @@ elif unformatted: - return True + NOT_YET_IMPLEMENTED_StmtIf -- return False -+ NOT_YET_IMPLEMENTED_StmtReturn + return False # Regression test for https://github.com/psf/black/issues/2567. @@ -162,14 +161,14 @@ elif unformatted: - ) : - # fmt: on - print ( "This won't be formatted" ) -- -- elif param[0:4] in ("ZZZZ",): -- print ( "This won't be formatted either" ) -- -- print("This will be formatted") +NOT_YET_IMPLEMENTED_StmtClassDef +- elif param[0:4] in ("ZZZZ",): +- print ( "This won't be formatted either" ) +- print("This will be formatted") +- +- # Regression test for https://github.com/psf/black/issues/2985. -class Named(t.Protocol): - # fmt: off @@ -181,10 +180,10 @@ elif unformatted: -class Factory(t.Protocol): - def this_will_be_formatted(self, **kwargs) -> Named: - ... +- +- # fmt: on +NOT_YET_IMPLEMENTED_StmtClassDef -- # fmt: on -- # Regression test for https://github.com/psf/black/issues/3436. -if x: @@ -212,7 +211,7 @@ def test_func(): # yapf: disable NOT_YET_IMPLEMENTED_StmtIf - NOT_YET_IMPLEMENTED_StmtReturn + return False # Regression test for https://github.com/psf/black/issues/2567. diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff_py.snap index b098d931af3134..7e6b71b7ad1836 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff_py.snap @@ -222,7 +222,7 @@ d={'a':1, # Comment 1 # Comment 2 -@@ -18,125 +16,127 @@ +@@ -18,109 +16,109 @@ # fmt: off def func_no_args(): @@ -241,7 +241,7 @@ d={'a':1, + NOT_YET_IMPLEMENTED_StmtIf + NOT_YET_IMPLEMENTED_StmtFor + NOT_IMPLEMENTED_call() -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return None + + async def coroutine(arg, exec=False): @@ -270,7 +270,7 @@ d={'a':1, + debug: bool = False, + **kwargs, +) -> str: -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] + + # fmt: on @@ -392,10 +392,7 @@ d={'a':1, # fmt: off # hey, that won't work - - # fmt: on -- pass -+ NOT_YET_IMPLEMENTED_StmtPass +@@ -130,13 +128,15 @@ def on_and_off_broken(): @@ -536,7 +533,7 @@ def func_no_args(): NOT_YET_IMPLEMENTED_StmtIf NOT_YET_IMPLEMENTED_StmtFor NOT_IMPLEMENTED_call() - NOT_YET_IMPLEMENTED_StmtReturn + return None async def coroutine(arg, exec=False): @@ -554,7 +551,7 @@ def function_signature_stress_test( debug: bool = False, **kwargs, ) -> str: - NOT_YET_IMPLEMENTED_StmtReturn + return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] # fmt: on @@ -637,7 +634,7 @@ def off_and_on_without_data(): # hey, that won't work # fmt: on - NOT_YET_IMPLEMENTED_StmtPass + pass def on_and_off_broken(): diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip8_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip8_py.snap index b51825420ff895..1b9c54b04853a3 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip8_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip8_py.snap @@ -79,10 +79,9 @@ async def test_async_with(): # Make sure a leading comment is not removed. -def some_func( unformatted, args ): # fmt: skip - print("I am some_func") -- return 0 +def some_func(unformatted, args): # fmt: skip + NOT_IMPLEMENTED_call() -+ NOT_YET_IMPLEMENTED_StmtReturn + return 0 # Make sure this comment is not removed. @@ -100,13 +99,13 @@ async def test_async_with(): - def some_method( self, unformatted, args ): # fmt: skip - print("I am some_method") - return 0 -+NOT_YET_IMPLEMENTED_StmtClassDef - +- - async def some_async_method( self, unformatted, args ): # fmt: skip - print("I am some_async_method") - await asyncio.sleep(1) ++NOT_YET_IMPLEMENTED_StmtClassDef + -- # Make sure a leading comment is not removed. -if unformatted_call( args ): # fmt: skip - print("First branch") @@ -161,7 +160,7 @@ async def test_async_with(): # Make sure a leading comment is not removed. def some_func(unformatted, args): # fmt: skip NOT_IMPLEMENTED_call() - NOT_YET_IMPLEMENTED_StmtReturn + return 0 # Make sure this comment is not removed. diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function2_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function2_py.snap index 28bde72abd5052..d4b5749cd38f0f 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function2_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function2_py.snap @@ -83,7 +83,7 @@ with hmm_but_this_should_get_two_preceding_newlines(): - ) + NOT_YET_IMPLEMENTED_StmtWith + NOT_IMPLEMENTED_call() # negate top -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return NOT_IMPLEMENTED_call() def g(): @@ -91,8 +91,7 @@ with hmm_but_this_should_get_two_preceding_newlines(): + "NOT_YET_IMPLEMENTED_STRING" def inner(): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass + pass - print("Inner defs should breathe a little.") + NOT_IMPLEMENTED_call() @@ -109,23 +108,22 @@ with hmm_but_this_should_get_two_preceding_newlines(): - import termios - - def i_should_be_followed_by_only_one_newline(): -- pass -- + pass + -elif os.name == "nt": - try: - import msvcrt -+ NOT_YET_IMPLEMENTED_StmtPass ++ NOT_IMPLEMENTED_call() - def i_should_be_followed_by_only_one_newline(): - pass -+ NOT_IMPLEMENTED_call() - except ImportError: ++NOT_YET_IMPLEMENTED_StmtIf - def i_should_be_followed_by_only_one_newline(): - pass -+NOT_YET_IMPLEMENTED_StmtIf - +- -elif False: - - class IHopeYouAreHavingALovelyDay: @@ -152,21 +150,21 @@ def f( ) -> A: NOT_YET_IMPLEMENTED_StmtWith NOT_IMPLEMENTED_call() # negate top - NOT_YET_IMPLEMENTED_StmtReturn + return NOT_IMPLEMENTED_call() def g(): "NOT_YET_IMPLEMENTED_STRING" def inner(): - NOT_YET_IMPLEMENTED_StmtPass + pass NOT_IMPLEMENTED_call() def h(): def inner(): - NOT_YET_IMPLEMENTED_StmtPass + pass NOT_IMPLEMENTED_call() diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_py.snap index acaaba2d80be81..4990f6f531fd4d 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_py.snap @@ -137,12 +137,11 @@ def __await__(): return (yield) - print(i) - continue - exec("new-style exec", {}, {}) -- return None + NOT_YET_IMPLEMENTED_StmtIf + NOT_YET_IMPLEMENTED_StmtIf + NOT_YET_IMPLEMENTED_StmtFor + NOT_IMPLEMENTED_call() -+ NOT_YET_IMPLEMENTED_StmtReturn + return None async def coroutine(arg, exec=False): @@ -169,7 +168,7 @@ def __await__(): return (yield) **kwargs, ) -> str: - return text[number:-1] -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] -def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""): @@ -295,12 +294,12 @@ def __await__(): return (yield) - **kwargs, - ) - ) -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return NOT_YET_IMPLEMENTED_ExprYieldFrom def __await__(): - return (yield) -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return NOT_YET_IMPLEMENTED_ExprYield ``` ## Ruff Output @@ -324,7 +323,7 @@ def func_no_args(): NOT_YET_IMPLEMENTED_StmtIf NOT_YET_IMPLEMENTED_StmtFor NOT_IMPLEMENTED_call() - NOT_YET_IMPLEMENTED_StmtReturn + return None async def coroutine(arg, exec=False): @@ -342,7 +341,7 @@ def function_signature_stress_test( debug: bool = False, **kwargs, ) -> str: - NOT_YET_IMPLEMENTED_StmtReturn + return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] def spaces( @@ -395,11 +394,11 @@ def f( a, **kwargs, ) -> A: - NOT_YET_IMPLEMENTED_StmtReturn + return NOT_YET_IMPLEMENTED_ExprYieldFrom def __await__(): - NOT_YET_IMPLEMENTED_StmtReturn + return NOT_YET_IMPLEMENTED_ExprYield ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_trailing_comma_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_trailing_comma_py.snap index 28da9c6a17094e..9850280e89c531 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_trailing_comma_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_trailing_comma_py.snap @@ -154,19 +154,8 @@ some_module.some_function( # The type annotation shouldn't get a trailing comma since that would change its type. -@@ -71,44 +31,25 @@ - def some_function_with_a_really_long_name() -> ( - returning_a_deeply_nested_import_of_a_type_i_suppose - ): -- pass -+ NOT_YET_IMPLEMENTED_StmtPass - - - def some_method_with_a_really_long_name( - very_long_parameter_so_yeah: str, another_long_parameter: int - ) -> another_case_of_returning_a_deeply_nested_import_of_a_type_i_suppose_cause_why_not: -- pass -+ NOT_YET_IMPLEMENTED_StmtPass +@@ -80,35 +40,16 @@ + pass -def func() -> ( @@ -174,9 +163,8 @@ some_module.some_function( - this_shouldn_t_get_a_trailing_comma_too - ) -): -- pass +def func() -> NOT_IMPLEMENTED_call(): -+ NOT_YET_IMPLEMENTED_StmtPass + pass -def func() -> ( @@ -184,9 +172,8 @@ some_module.some_function( - this_shouldn_t_get_a_trailing_comma_too - ) -): -- pass +def func() -> NOT_IMPLEMENTED_call(): -+ NOT_YET_IMPLEMENTED_StmtPass + pass # Make sure inner one-element tuple won't explode @@ -245,21 +232,21 @@ def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] def some_function_with_a_really_long_name() -> ( returning_a_deeply_nested_import_of_a_type_i_suppose ): - NOT_YET_IMPLEMENTED_StmtPass + pass def some_method_with_a_really_long_name( very_long_parameter_so_yeah: str, another_long_parameter: int ) -> another_case_of_returning_a_deeply_nested_import_of_a_type_i_suppose_cause_why_not: - NOT_YET_IMPLEMENTED_StmtPass + pass def func() -> NOT_IMPLEMENTED_call(): - NOT_YET_IMPLEMENTED_StmtPass + pass def func() -> NOT_IMPLEMENTED_call(): - NOT_YET_IMPLEMENTED_StmtPass + pass # Make sure inner one-element tuple won't explode diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__power_op_spacing_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__power_op_spacing_py.snap index 09cb4603fb0616..56b3a0ef5a8abe 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__power_op_spacing_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__power_op_spacing_py.snap @@ -76,14 +76,6 @@ return np.divide( ```diff --- Black +++ Ruff -@@ -1,6 +1,6 @@ - def function(**kwargs): - t = a**2 + b**3 -- return t**2 -+ NOT_YET_IMPLEMENTED_StmtReturn - - - def function_replace_spaces(**kwargs): @@ -8,56 +8,48 @@ @@ -185,7 +177,7 @@ return np.divide( ```py def function(**kwargs): t = a**2 + b**3 - NOT_YET_IMPLEMENTED_StmtReturn + return t**2 def function_replace_spaces(**kwargs): diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_parens_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_parens_py.snap index b72cb08288e8d5..5e1e16cd2ebc1b 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_parens_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_parens_py.snap @@ -68,7 +68,7 @@ def example8(): ```diff --- Black +++ Ruff -@@ -1,85 +1,49 @@ +@@ -1,24 +1,16 @@ x = 1 x = 1.2 @@ -92,46 +92,39 @@ def example8(): def example(): - return "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return "NOT_YET_IMPLEMENTED_STRING" def example1(): -- return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111 -+ NOT_YET_IMPLEMENTED_StmtReturn - - - def example1point5(): -- return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111 -+ NOT_YET_IMPLEMENTED_StmtReturn +@@ -30,15 +22,11 @@ def example2(): - return ( - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - ) -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return "NOT_YET_IMPLEMENTED_STRING" def example3(): - return ( - 1111111111111111111111111111111111111111111111111111111111111111111111111111111 - ) -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return 1111111111111111111111111111111111111111111111111111111111111111111111111111111 def example4(): -- return True -+ NOT_YET_IMPLEMENTED_StmtReturn +@@ -46,39 +34,15 @@ def example5(): - return () -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return (1, 2) def example6(): - return {a: a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]} -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict} def example7(): @@ -160,12 +153,10 @@ def example8(): - 20000000000000000000, - ] - } -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict} def example8(): -- return None -+ NOT_YET_IMPLEMENTED_StmtReturn ``` ## Ruff Output @@ -183,43 +174,43 @@ async def show_status(): def example(): - NOT_YET_IMPLEMENTED_StmtReturn + return "NOT_YET_IMPLEMENTED_STRING" def example1(): - NOT_YET_IMPLEMENTED_StmtReturn + return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111 def example1point5(): - NOT_YET_IMPLEMENTED_StmtReturn + return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111 def example2(): - NOT_YET_IMPLEMENTED_StmtReturn + return "NOT_YET_IMPLEMENTED_STRING" def example3(): - NOT_YET_IMPLEMENTED_StmtReturn + return 1111111111111111111111111111111111111111111111111111111111111111111111111111111 def example4(): - NOT_YET_IMPLEMENTED_StmtReturn + return True def example5(): - NOT_YET_IMPLEMENTED_StmtReturn + return (1, 2) def example6(): - NOT_YET_IMPLEMENTED_StmtReturn + return {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict} def example7(): - NOT_YET_IMPLEMENTED_StmtReturn + return {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict} def example8(): - NOT_YET_IMPLEMENTED_StmtReturn + return None ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__return_annotation_brackets_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__return_annotation_brackets_py.snap index af243a6970133b..404098c4317aa1 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__return_annotation_brackets_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__return_annotation_brackets_py.snap @@ -101,126 +101,35 @@ def foo() -> tuple[int, int, int,]: ```diff --- Black +++ Ruff -@@ -1,61 +1,65 @@ - # Control - def double(a: int) -> int: -- return 2 * a -+ NOT_YET_IMPLEMENTED_StmtReturn - - - # Remove the brackets - def double(a: int) -> int: -- return 2 * a -+ NOT_YET_IMPLEMENTED_StmtReturn - - - # Some newline variations - def double(a: int) -> int: -- return 2 * a -+ NOT_YET_IMPLEMENTED_StmtReturn - - - def double(a: int) -> int: -- return 2 * a -+ NOT_YET_IMPLEMENTED_StmtReturn - - - def double(a: int) -> int: -- return 2 * a -+ NOT_YET_IMPLEMENTED_StmtReturn - - - # Don't lose the comments - def double(a: int) -> int: # Hello -- return 2 * a -+ NOT_YET_IMPLEMENTED_StmtReturn +@@ -26,7 +26,9 @@ + return 2 * a -def double(a: int) -> int: # Hello -- return 2 * a +def double(a: int) -> ( + int # Hello +): -+ NOT_YET_IMPLEMENTED_StmtReturn - - - # Really long annotations - def foo() -> ( - intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds - ): -- return 2 -+ NOT_YET_IMPLEMENTED_StmtReturn + return 2 * a - def foo() -> ( - intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds - ): -- return 2 -+ NOT_YET_IMPLEMENTED_StmtReturn - - - def foo() -> ( - intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds - | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds - ): -- return 2 -+ NOT_YET_IMPLEMENTED_StmtReturn - - - def foo( +@@ -54,7 +56,9 @@ a: int, b: int, c: int, -) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: -- return 2 +) -> ( + intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds +): -+ NOT_YET_IMPLEMENTED_StmtReturn - - - def foo( -@@ -66,7 +70,7 @@ - intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds - | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds - ): -- return 2 -+ NOT_YET_IMPLEMENTED_StmtReturn - - - # Split args but no need to split return -@@ -75,46 +79,34 @@ - b: int, - c: int, - ) -> int: -- return 2 -+ NOT_YET_IMPLEMENTED_StmtReturn - + return 2 - # Deeply nested brackets - # with *interesting* spacing - def double(a: int) -> int: -- return 2 * a -+ NOT_YET_IMPLEMENTED_StmtReturn - - def double(a: int) -> int: -- return 2 * a -+ NOT_YET_IMPLEMENTED_StmtReturn - - - def foo() -> ( - intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds - ): -- return 2 -+ NOT_YET_IMPLEMENTED_StmtReturn +@@ -95,26 +99,14 @@ # Return type with commas -def foo() -> tuple[int, int, int]: -- return 2 +def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]: -+ NOT_YET_IMPLEMENTED_StmtReturn + return 2 -def foo() -> ( @@ -230,9 +139,8 @@ def foo() -> tuple[int, int, int,]: - loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, - ] -): -- return 2 +def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]: -+ NOT_YET_IMPLEMENTED_StmtReturn + return 2 # Magic trailing comma example @@ -243,9 +151,8 @@ def foo() -> tuple[int, int, int,]: - int, - ] -): -- return 2 +def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]: -+ NOT_YET_IMPLEMENTED_StmtReturn + return 2 ``` ## Ruff Output @@ -253,56 +160,56 @@ def foo() -> tuple[int, int, int,]: ```py # Control def double(a: int) -> int: - NOT_YET_IMPLEMENTED_StmtReturn + return 2 * a # Remove the brackets def double(a: int) -> int: - NOT_YET_IMPLEMENTED_StmtReturn + return 2 * a # Some newline variations def double(a: int) -> int: - NOT_YET_IMPLEMENTED_StmtReturn + return 2 * a def double(a: int) -> int: - NOT_YET_IMPLEMENTED_StmtReturn + return 2 * a def double(a: int) -> int: - NOT_YET_IMPLEMENTED_StmtReturn + return 2 * a # Don't lose the comments def double(a: int) -> int: # Hello - NOT_YET_IMPLEMENTED_StmtReturn + return 2 * a def double(a: int) -> ( int # Hello ): - NOT_YET_IMPLEMENTED_StmtReturn + return 2 * a # Really long annotations def foo() -> ( intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds ): - NOT_YET_IMPLEMENTED_StmtReturn + return 2 def foo() -> ( intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds ): - NOT_YET_IMPLEMENTED_StmtReturn + return 2 def foo() -> ( intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds ): - NOT_YET_IMPLEMENTED_StmtReturn + return 2 def foo( @@ -312,7 +219,7 @@ def foo( ) -> ( intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds ): - NOT_YET_IMPLEMENTED_StmtReturn + return 2 def foo( @@ -323,7 +230,7 @@ def foo( intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds ): - NOT_YET_IMPLEMENTED_StmtReturn + return 2 # Split args but no need to split return @@ -332,37 +239,37 @@ def foo( b: int, c: int, ) -> int: - NOT_YET_IMPLEMENTED_StmtReturn + return 2 # Deeply nested brackets # with *interesting* spacing def double(a: int) -> int: - NOT_YET_IMPLEMENTED_StmtReturn + return 2 * a def double(a: int) -> int: - NOT_YET_IMPLEMENTED_StmtReturn + return 2 * a def foo() -> ( intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds ): - NOT_YET_IMPLEMENTED_StmtReturn + return 2 # Return type with commas def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]: - NOT_YET_IMPLEMENTED_StmtReturn + return 2 def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]: - NOT_YET_IMPLEMENTED_StmtReturn + return 2 # Magic trailing comma example def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]: - NOT_YET_IMPLEMENTED_StmtReturn + return 2 ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__torture_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__torture_py.snap index e0d11f0e2f2736..0aee58f5ca4e37 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__torture_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__torture_py.snap @@ -99,7 +99,7 @@ assert ( - othr.meta_data, - othr.schedule, - ) -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -assert a_function( @@ -130,7 +130,7 @@ NOT_YET_IMPLEMENTED_StmtClassDef def test(self, othr): - NOT_YET_IMPLEMENTED_StmtReturn + return NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 NOT_YET_IMPLEMENTED_StmtAssert diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_commas_in_leading_parts_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_commas_in_leading_parts_py.snap index 796c970ff77aca..d1a1d68ab9bc9d 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_commas_in_leading_parts_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_commas_in_leading_parts_py.snap @@ -86,7 +86,7 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx( - }, - api_key=api_key, - )["extensions"]["sdk"]["token"] -+ NOT_YET_IMPLEMENTED_StmtReturn ++ return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] # Edge case where a bug in a working-in-progress version of @@ -121,7 +121,7 @@ NOT_IMPLEMENTED_call() # Example from https://github.com/psf/black/issues/3229 def refresh_token(self, device_family, refresh_token, api_key): - NOT_YET_IMPLEMENTED_StmtReturn + return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] # Edge case where a bug in a working-in-progress version of diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__function_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__function_py.snap index 9533b18df570af..3d448396f60dab 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__function_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__function_py.snap @@ -101,13 +101,13 @@ def test( ### Different function argument wrappings def single_line(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc): - NOT_YET_IMPLEMENTED_StmtPass + pass def arguments_on_their_own_line( aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccc, ddddddddddddd, eeeeeee ): - NOT_YET_IMPLEMENTED_StmtPass + pass def argument_per_line( @@ -118,7 +118,7 @@ def argument_per_line( eeeeeeeeeeeeeeee, ffffffffffff, ): - NOT_YET_IMPLEMENTED_StmtPass + pass def last_pos_only_trailing_comma( @@ -126,11 +126,11 @@ def last_pos_only_trailing_comma( b, /, ): - NOT_YET_IMPLEMENTED_StmtPass + pass def last_pos_no_trailing_comma(a, b, /): - NOT_YET_IMPLEMENTED_StmtPass + pass def varg_with_leading_comments( diff --git a/crates/ruff_python_formatter/src/statement/suite.rs b/crates/ruff_python_formatter/src/statement/suite.rs index ff81ad7fb555ba..23b98f179895a0 100644 --- a/crates/ruff_python_formatter/src/statement/suite.rs +++ b/crates/ruff_python_formatter/src/statement/suite.rs @@ -259,11 +259,11 @@ trailing_statement = 1 def func(): - NOT_YET_IMPLEMENTED_StmtPass + pass def trailing_func(): - NOT_YET_IMPLEMENTED_StmtPass + pass "# ); } @@ -288,10 +288,10 @@ NOT_YET_IMPLEMENTED_StmtClassDef trailing_statement = 1 def func(): - NOT_YET_IMPLEMENTED_StmtPass + pass def trailing_func(): - NOT_YET_IMPLEMENTED_StmtPass + pass "# ); }