diff --git a/crates/ruff_python_formatter/src/builders.rs b/crates/ruff_python_formatter/src/builders.rs index 847df4d3c5..36ea6d6b2a 100644 --- a/crates/ruff_python_formatter/src/builders.rs +++ b/crates/ruff_python_formatter/src/builders.rs @@ -191,16 +191,16 @@ no_leading_newline = 30 assert_eq!( &printed, - r#"a = 10 + r#"NOT_YET_IMPLEMENTED_StmtAssign -three_leading_newlines = 80 +NOT_YET_IMPLEMENTED_StmtAssign -two_leading_newlines = 20 +NOT_YET_IMPLEMENTED_StmtAssign -one_leading_newline = 10 -no_leading_newline = 30"# +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign"# ); } @@ -211,14 +211,14 @@ no_leading_newline = 30"# assert_eq!( &printed, - r#"a = 10 + r#"NOT_YET_IMPLEMENTED_StmtAssign -three_leading_newlines = 80 +NOT_YET_IMPLEMENTED_StmtAssign -two_leading_newlines = 20 +NOT_YET_IMPLEMENTED_StmtAssign -one_leading_newline = 10 -no_leading_newline = 30"# +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign"# ); } @@ -229,11 +229,11 @@ no_leading_newline = 30"# assert_eq!( &printed, - r#"a = 10 -three_leading_newlines = 80 -two_leading_newlines = 20 -one_leading_newline = 10 -no_leading_newline = 30"# + r#"NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign"# ); } } diff --git a/crates/ruff_python_formatter/src/expression/expr_attribute.rs b/crates/ruff_python_formatter/src/expression/expr_attribute.rs index 71aa2e83f8..6c8e8962b2 100644 --- a/crates/ruff_python_formatter/src/expression/expr_attribute.rs +++ b/crates/ruff_python_formatter/src/expression/expr_attribute.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprAttribute; @@ -10,7 +10,7 @@ pub struct FormatExprAttribute; impl FormatNodeRule for FormatExprAttribute { fn fmt_fields(&self, item: &ExprAttribute, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_await.rs b/crates/ruff_python_formatter/src/expression/expr_await.rs index 60651ce674..82c8e307e1 100644 --- a/crates/ruff_python_formatter/src/expression/expr_await.rs +++ b/crates/ruff_python_formatter/src/expression/expr_await.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprAwait; @@ -10,7 +10,7 @@ pub struct FormatExprAwait; impl FormatNodeRule for FormatExprAwait { fn fmt_fields(&self, item: &ExprAwait, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } 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 a3ae0b7cf0..9ec98d7722 100644 --- a/crates/ruff_python_formatter/src/expression/expr_bool_op.rs +++ b/crates/ruff_python_formatter/src/expression/expr_bool_op.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprBoolOp; @@ -10,7 +10,7 @@ pub struct FormatExprBoolOp; impl FormatNodeRule for FormatExprBoolOp { fn fmt_fields(&self, item: &ExprBoolOp, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_call.rs b/crates/ruff_python_formatter/src/expression/expr_call.rs index 5a2076a7d4..ae3513e50f 100644 --- a/crates/ruff_python_formatter/src/expression/expr_call.rs +++ b/crates/ruff_python_formatter/src/expression/expr_call.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprCall; @@ -10,7 +10,7 @@ pub struct FormatExprCall; impl FormatNodeRule for FormatExprCall { fn fmt_fields(&self, item: &ExprCall, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_compare.rs b/crates/ruff_python_formatter/src/expression/expr_compare.rs index 7915151cf5..14333cfd51 100644 --- a/crates/ruff_python_formatter/src/expression/expr_compare.rs +++ b/crates/ruff_python_formatter/src/expression/expr_compare.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprCompare; @@ -10,7 +10,7 @@ pub struct FormatExprCompare; impl FormatNodeRule for FormatExprCompare { fn fmt_fields(&self, item: &ExprCompare, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_constant.rs b/crates/ruff_python_formatter/src/expression/expr_constant.rs index 9a69fec5c7..0b4d3d96af 100644 --- a/crates/ruff_python_formatter/src/expression/expr_constant.rs +++ b/crates/ruff_python_formatter/src/expression/expr_constant.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprConstant; @@ -10,7 +10,7 @@ pub struct FormatExprConstant; impl FormatNodeRule for FormatExprConstant { fn fmt_fields(&self, item: &ExprConstant, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_dict.rs b/crates/ruff_python_formatter/src/expression/expr_dict.rs index c9926b822d..c44db9b39c 100644 --- a/crates/ruff_python_formatter/src/expression/expr_dict.rs +++ b/crates/ruff_python_formatter/src/expression/expr_dict.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprDict; @@ -10,7 +10,7 @@ pub struct FormatExprDict; impl FormatNodeRule for FormatExprDict { fn fmt_fields(&self, item: &ExprDict, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } 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 6052a2ecd5..9d35e5ee1f 100644 --- a/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprDictComp; @@ -10,7 +10,7 @@ pub struct FormatExprDictComp; impl FormatNodeRule for FormatExprDictComp { fn fmt_fields(&self, item: &ExprDictComp, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } 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 f66302b9e6..9578106113 100644 --- a/crates/ruff_python_formatter/src/expression/expr_formatted_value.rs +++ b/crates/ruff_python_formatter/src/expression/expr_formatted_value.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprFormattedValue; @@ -10,7 +10,7 @@ pub struct FormatExprFormattedValue; impl FormatNodeRule for FormatExprFormattedValue { fn fmt_fields(&self, item: &ExprFormattedValue, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } 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 7ee276e5ad..c62fdfb070 100644 --- a/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprGeneratorExp; @@ -10,7 +10,7 @@ pub struct FormatExprGeneratorExp; impl FormatNodeRule for FormatExprGeneratorExp { fn fmt_fields(&self, item: &ExprGeneratorExp, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } 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 b13162413c..7357abd3a9 100644 --- a/crates/ruff_python_formatter/src/expression/expr_if_exp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_if_exp.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprIfExp; @@ -10,7 +10,7 @@ pub struct FormatExprIfExp; impl FormatNodeRule for FormatExprIfExp { fn fmt_fields(&self, item: &ExprIfExp, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } 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 235f712bba..86194c9b2b 100644 --- a/crates/ruff_python_formatter/src/expression/expr_joined_str.rs +++ b/crates/ruff_python_formatter/src/expression/expr_joined_str.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprJoinedStr; @@ -10,7 +10,7 @@ pub struct FormatExprJoinedStr; impl FormatNodeRule for FormatExprJoinedStr { fn fmt_fields(&self, item: &ExprJoinedStr, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_lambda.rs b/crates/ruff_python_formatter/src/expression/expr_lambda.rs index a9b081c91e..7106feefc6 100644 --- a/crates/ruff_python_formatter/src/expression/expr_lambda.rs +++ b/crates/ruff_python_formatter/src/expression/expr_lambda.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprLambda; @@ -10,7 +10,7 @@ pub struct FormatExprLambda; impl FormatNodeRule for FormatExprLambda { fn fmt_fields(&self, item: &ExprLambda, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } 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 e95327faed..e91c16f532 100644 --- a/crates/ruff_python_formatter/src/expression/expr_list_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_list_comp.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprListComp; @@ -10,7 +10,7 @@ pub struct FormatExprListComp; impl FormatNodeRule for FormatExprListComp { fn fmt_fields(&self, item: &ExprListComp, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } 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 ca7182604c..4cf013217d 100644 --- a/crates/ruff_python_formatter/src/expression/expr_named_expr.rs +++ b/crates/ruff_python_formatter/src/expression/expr_named_expr.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprNamedExpr; @@ -10,7 +10,7 @@ pub struct FormatExprNamedExpr; impl FormatNodeRule for FormatExprNamedExpr { fn fmt_fields(&self, item: &ExprNamedExpr, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_set.rs b/crates/ruff_python_formatter/src/expression/expr_set.rs index 283ea6370e..4184c85472 100644 --- a/crates/ruff_python_formatter/src/expression/expr_set.rs +++ b/crates/ruff_python_formatter/src/expression/expr_set.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprSet; @@ -10,7 +10,7 @@ pub struct FormatExprSet; impl FormatNodeRule for FormatExprSet { fn fmt_fields(&self, item: &ExprSet, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } 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 a74829aee4..df3405a2c9 100644 --- a/crates/ruff_python_formatter/src/expression/expr_set_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_set_comp.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprSetComp; @@ -10,7 +10,7 @@ pub struct FormatExprSetComp; impl FormatNodeRule for FormatExprSetComp { fn fmt_fields(&self, item: &ExprSetComp, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_slice.rs b/crates/ruff_python_formatter/src/expression/expr_slice.rs index 8b019564d6..5c08f110d4 100644 --- a/crates/ruff_python_formatter/src/expression/expr_slice.rs +++ b/crates/ruff_python_formatter/src/expression/expr_slice.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprSlice; @@ -10,7 +10,7 @@ pub struct FormatExprSlice; impl FormatNodeRule for FormatExprSlice { fn fmt_fields(&self, item: &ExprSlice, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_starred.rs b/crates/ruff_python_formatter/src/expression/expr_starred.rs index 14e40a26d8..c06a64aaa3 100644 --- a/crates/ruff_python_formatter/src/expression/expr_starred.rs +++ b/crates/ruff_python_formatter/src/expression/expr_starred.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprStarred; @@ -10,7 +10,7 @@ pub struct FormatExprStarred; impl FormatNodeRule for FormatExprStarred { fn fmt_fields(&self, item: &ExprStarred, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_subscript.rs b/crates/ruff_python_formatter/src/expression/expr_subscript.rs index 4efa5c914c..dc02ae90b7 100644 --- a/crates/ruff_python_formatter/src/expression/expr_subscript.rs +++ b/crates/ruff_python_formatter/src/expression/expr_subscript.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprSubscript; @@ -10,7 +10,7 @@ pub struct FormatExprSubscript; impl FormatNodeRule for FormatExprSubscript { fn fmt_fields(&self, item: &ExprSubscript, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_tuple.rs b/crates/ruff_python_formatter/src/expression/expr_tuple.rs index 2b687b3787..c088007719 100644 --- a/crates/ruff_python_formatter/src/expression/expr_tuple.rs +++ b/crates/ruff_python_formatter/src/expression/expr_tuple.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprTuple; @@ -10,7 +10,7 @@ pub struct FormatExprTuple; impl FormatNodeRule for FormatExprTuple { fn fmt_fields(&self, item: &ExprTuple, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } 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 c97bc8a56c..8df9831255 100644 --- a/crates/ruff_python_formatter/src/expression/expr_unary_op.rs +++ b/crates/ruff_python_formatter/src/expression/expr_unary_op.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprUnaryOp; @@ -10,7 +10,7 @@ pub struct FormatExprUnaryOp; impl FormatNodeRule for FormatExprUnaryOp { fn fmt_fields(&self, item: &ExprUnaryOp, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_yield.rs b/crates/ruff_python_formatter/src/expression/expr_yield.rs index 0d59010bbb..7e9f27f5da 100644 --- a/crates/ruff_python_formatter/src/expression/expr_yield.rs +++ b/crates/ruff_python_formatter/src/expression/expr_yield.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprYield; @@ -10,7 +10,7 @@ pub struct FormatExprYield; impl FormatNodeRule for FormatExprYield { fn fmt_fields(&self, item: &ExprYield, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } 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 b0218e1561..5ed9bd6354 100644 --- a/crates/ruff_python_formatter/src/expression/expr_yield_from.rs +++ b/crates/ruff_python_formatter/src/expression/expr_yield_from.rs @@ -1,7 +1,7 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExprYieldFrom; @@ -10,7 +10,7 @@ pub struct FormatExprYieldFrom; impl FormatNodeRule for FormatExprYieldFrom { fn fmt_fields(&self, item: &ExprYieldFrom, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/lib.rs b/crates/ruff_python_formatter/src/lib.rs index 99d735de87..c0fbaca55c 100644 --- a/crates/ruff_python_formatter/src/lib.rs +++ b/crates/ruff_python_formatter/src/lib.rs @@ -1,22 +1,15 @@ use anyhow::{anyhow, Context, Result}; -use ruff_text_size::TextRange; -use rustpython_parser::ast::Mod; +use ruff_formatter::prelude::*; +use ruff_formatter::{format, write}; +use ruff_formatter::{Formatted, IndentStyle, Printed, SimpleFormatOptions, SourceCode}; +use ruff_python_ast::node::{AnyNodeRef, AstNode, NodeKind}; +use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder, Locator}; +use ruff_text_size::{TextLen, TextRange}; +use rustpython_parser::ast::{Mod, Ranged}; use rustpython_parser::lexer::lex; use rustpython_parser::{parse_tokens, Mode}; use std::borrow::Cow; -use ruff_formatter::format_element::tag::VerbatimKind; -use ruff_formatter::formatter::Formatter; -use ruff_formatter::prelude::{ - dynamic_text, source_position, source_text_slice, ContainsNewlines, Tag, -}; -use ruff_formatter::{ - format, normalize_newlines, write, Buffer, Format, FormatElement, FormatResult, Formatted, - IndentStyle, Printed, SimpleFormatOptions, SourceCode, -}; -use ruff_python_ast::node::AstNode; -use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder, Locator}; - use crate::comments::{ dangling_node_comments, leading_node_comments, trailing_node_comments, Comments, }; @@ -142,16 +135,49 @@ pub fn format_node<'a>( ) } +pub(crate) struct NotYetImplemented(NodeKind); + +/// Formats a placeholder for nodes that have not yet been implemented +pub(crate) fn not_yet_implemented<'a, T>(node: T) -> NotYetImplemented +where + T: Into>, +{ + NotYetImplemented(node.into().kind()) +} + +impl Format> for NotYetImplemented { + fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> { + let text = std::format!("NOT_YET_IMPLEMENTED_{:?}", self.0); + + f.write_element(FormatElement::Tag(Tag::StartVerbatim( + tag::VerbatimKind::Verbatim { + length: text.text_len(), + }, + )))?; + + f.write_element(FormatElement::DynamicText { + text: Box::from(text), + })?; + + f.write_element(FormatElement::Tag(Tag::EndVerbatim))?; + Ok(()) + } +} + pub(crate) struct VerbatimText(TextRange); -pub(crate) const fn verbatim_text(range: TextRange) -> VerbatimText { - VerbatimText(range) +#[allow(unused)] +pub(crate) fn verbatim_text(item: &T) -> VerbatimText +where + T: Ranged, +{ + VerbatimText(item.range()) } impl Format> for VerbatimText { fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> { f.write_element(FormatElement::Tag(Tag::StartVerbatim( - VerbatimKind::Verbatim { + tag::VerbatimKind::Verbatim { length: self.0.len(), }, )))?; @@ -203,8 +229,7 @@ if True: # trailing "#; let expected = r#"# preceding -if True: - print( "hi" ) +NOT_YET_IMPLEMENTED_StmtIf # trailing "#; let actual = format_module(input)?.as_code().to_string(); diff --git a/crates/ruff_python_formatter/src/module/mod_expression.rs b/crates/ruff_python_formatter/src/module/mod_expression.rs index 0bf1a2a5f6..d7a8c40db6 100644 --- a/crates/ruff_python_formatter/src/module/mod_expression.rs +++ b/crates/ruff_python_formatter/src/module/mod_expression.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ModExpression; @@ -7,6 +7,6 @@ pub struct FormatModExpression; impl FormatNodeRule for FormatModExpression { fn fmt_fields(&self, item: &ModExpression, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/module/mod_function_type.rs b/crates/ruff_python_formatter/src/module/mod_function_type.rs index 90abfaa624..822d7d9553 100644 --- a/crates/ruff_python_formatter/src/module/mod_function_type.rs +++ b/crates/ruff_python_formatter/src/module/mod_function_type.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ModFunctionType; @@ -7,6 +7,6 @@ pub struct FormatModFunctionType; impl FormatNodeRule for FormatModFunctionType { fn fmt_fields(&self, item: &ModFunctionType, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/module/mod_interactive.rs b/crates/ruff_python_formatter/src/module/mod_interactive.rs index c84e60fb27..2477a1b18d 100644 --- a/crates/ruff_python_formatter/src/module/mod_interactive.rs +++ b/crates/ruff_python_formatter/src/module/mod_interactive.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ModInteractive; @@ -7,6 +7,6 @@ pub struct FormatModInteractive; impl FormatNodeRule for FormatModInteractive { fn fmt_fields(&self, item: &ModInteractive, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/other/alias.rs b/crates/ruff_python_formatter/src/other/alias.rs index 25db0f34d7..8a1501e09c 100644 --- a/crates/ruff_python_formatter/src/other/alias.rs +++ b/crates/ruff_python_formatter/src/other/alias.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::Alias; @@ -7,6 +7,6 @@ pub struct FormatAlias; impl FormatNodeRule for FormatAlias { fn fmt_fields(&self, item: &Alias, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/other/arg.rs b/crates/ruff_python_formatter/src/other/arg.rs index 03a6df966a..44bb3e85e4 100644 --- a/crates/ruff_python_formatter/src/other/arg.rs +++ b/crates/ruff_python_formatter/src/other/arg.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::Arg; @@ -7,6 +7,6 @@ pub struct FormatArg; impl FormatNodeRule for FormatArg { fn fmt_fields(&self, item: &Arg, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/other/arguments.rs b/crates/ruff_python_formatter/src/other/arguments.rs index ab4e3d1d83..ee0d7b872f 100644 --- a/crates/ruff_python_formatter/src/other/arguments.rs +++ b/crates/ruff_python_formatter/src/other/arguments.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::Arguments; @@ -7,6 +7,6 @@ pub struct FormatArguments; impl FormatNodeRule for FormatArguments { fn fmt_fields(&self, item: &Arguments, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/other/comprehension.rs b/crates/ruff_python_formatter/src/other/comprehension.rs index 19354cbde8..edf64d8bee 100644 --- a/crates/ruff_python_formatter/src/other/comprehension.rs +++ b/crates/ruff_python_formatter/src/other/comprehension.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::Comprehension; @@ -7,6 +7,6 @@ pub struct FormatComprehension; impl FormatNodeRule for FormatComprehension { fn fmt_fields(&self, item: &Comprehension, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/other/excepthandler_except_handler.rs b/crates/ruff_python_formatter/src/other/excepthandler_except_handler.rs index ccdeb1ae0e..a5826413fc 100644 --- a/crates/ruff_python_formatter/src/other/excepthandler_except_handler.rs +++ b/crates/ruff_python_formatter/src/other/excepthandler_except_handler.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::ExcepthandlerExceptHandler; @@ -11,6 +11,6 @@ impl FormatNodeRule for FormatExcepthandlerExceptHan item: &ExcepthandlerExceptHandler, f: &mut PyFormatter, ) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/other/keyword.rs b/crates/ruff_python_formatter/src/other/keyword.rs index 078429f980..7998efc47c 100644 --- a/crates/ruff_python_formatter/src/other/keyword.rs +++ b/crates/ruff_python_formatter/src/other/keyword.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::Keyword; @@ -7,6 +7,6 @@ pub struct FormatKeyword; impl FormatNodeRule for FormatKeyword { fn fmt_fields(&self, item: &Keyword, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/other/match_case.rs b/crates/ruff_python_formatter/src/other/match_case.rs index af486257f5..f4b79d1960 100644 --- a/crates/ruff_python_formatter/src/other/match_case.rs +++ b/crates/ruff_python_formatter/src/other/match_case.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::MatchCase; @@ -7,6 +7,6 @@ pub struct FormatMatchCase; impl FormatNodeRule for FormatMatchCase { fn fmt_fields(&self, item: &MatchCase, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/other/type_ignore_type_ignore.rs b/crates/ruff_python_formatter/src/other/type_ignore_type_ignore.rs index 937e99db7c..b622a705e3 100644 --- a/crates/ruff_python_formatter/src/other/type_ignore_type_ignore.rs +++ b/crates/ruff_python_formatter/src/other/type_ignore_type_ignore.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::TypeIgnoreTypeIgnore; @@ -7,6 +7,6 @@ pub struct FormatTypeIgnoreTypeIgnore; impl FormatNodeRule for FormatTypeIgnoreTypeIgnore { fn fmt_fields(&self, item: &TypeIgnoreTypeIgnore, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/other/withitem.rs b/crates/ruff_python_formatter/src/other/withitem.rs index 3b8ace3eb0..7edf9ea116 100644 --- a/crates/ruff_python_formatter/src/other/withitem.rs +++ b/crates/ruff_python_formatter/src/other/withitem.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::Withitem; @@ -7,6 +7,6 @@ pub struct FormatWithitem; impl FormatNodeRule for FormatWithitem { fn fmt_fields(&self, item: &Withitem, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_as.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_as.rs index c91b210e3f..3f67d87b93 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_as.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_as.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::PatternMatchAs; @@ -7,6 +7,6 @@ pub struct FormatPatternMatchAs; impl FormatNodeRule for FormatPatternMatchAs { fn fmt_fields(&self, item: &PatternMatchAs, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_class.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_class.rs index e1987acd95..a64f4b2207 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_class.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_class.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::PatternMatchClass; @@ -7,6 +7,6 @@ pub struct FormatPatternMatchClass; impl FormatNodeRule for FormatPatternMatchClass { fn fmt_fields(&self, item: &PatternMatchClass, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs index 0afe64d3c8..b3fca1d5d4 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_mapping.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::PatternMatchMapping; @@ -7,6 +7,6 @@ pub struct FormatPatternMatchMapping; impl FormatNodeRule for FormatPatternMatchMapping { fn fmt_fields(&self, item: &PatternMatchMapping, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_or.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_or.rs index 2fa18ac9e8..487e884ec8 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_or.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_or.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::PatternMatchOr; @@ -7,6 +7,6 @@ pub struct FormatPatternMatchOr; impl FormatNodeRule for FormatPatternMatchOr { fn fmt_fields(&self, item: &PatternMatchOr, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_sequence.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_sequence.rs index 6159a17490..c2fa31ecf9 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_sequence.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_sequence.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::PatternMatchSequence; @@ -7,6 +7,6 @@ pub struct FormatPatternMatchSequence; impl FormatNodeRule for FormatPatternMatchSequence { fn fmt_fields(&self, item: &PatternMatchSequence, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_singleton.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_singleton.rs index a35b506e16..352098e9d1 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_singleton.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_singleton.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::PatternMatchSingleton; @@ -7,6 +7,6 @@ pub struct FormatPatternMatchSingleton; impl FormatNodeRule for FormatPatternMatchSingleton { fn fmt_fields(&self, item: &PatternMatchSingleton, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_star.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_star.rs index cd5f4976f5..17340ae840 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_star.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_star.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::PatternMatchStar; @@ -7,6 +7,6 @@ pub struct FormatPatternMatchStar; impl FormatNodeRule for FormatPatternMatchStar { fn fmt_fields(&self, item: &PatternMatchStar, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_value.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_value.rs index 4d14f2aad0..9a57fbd15a 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_value.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_value.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::PatternMatchValue; @@ -7,6 +7,6 @@ pub struct FormatPatternMatchValue; impl FormatNodeRule for FormatPatternMatchValue { fn fmt_fields(&self, item: &PatternMatchValue, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__attribute_access_on_number_literals_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__attribute_access_on_number_literals_py.snap index 0128d6ed45..cf7719b9a4 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__attribute_access_on_number_literals_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__attribute_access_on_number_literals_py.snap @@ -35,10 +35,9 @@ y = 100(no) ```diff --- Black +++ Ruff -@@ -1,21 +1,21 @@ +@@ -1,22 +1,21 @@ -x = (123456789).bit_count() -+x = 123456789 .bit_count() - x = (123456).__abs__() +-x = (123456).__abs__() -x = (0.1).is_integer() -x = (1.0).imag -x = (1e1).imag @@ -53,53 +52,57 @@ y = 100(no) -x = 0o777.real -x = (0.000000006).hex() -x = -100.0000j -+x = .1.is_integer() -+x = 1. .imag -+x = 1E+1.imag -+x = 1E-1.real -+x = 123456789.123456789.hex() -+x = 123456789.123456789E123456789 .real -+x = 123456789E123456789 .conjugate() -+x = 123456789J.real -+x = 123456789.123456789J.__add__(0b1011.bit_length()) -+x = 0XB1ACC.conjugate() -+x = 0B1011 .conjugate() -+x = 0O777 .real -+x = 0.000000006 .hex() -+x = -100.0000J ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign -if (10).real: -+if 10 .real: - ... +- ... ++NOT_YET_IMPLEMENTED_StmtIf - y = 100[no] +-y = 100[no] +-y = 100(no) ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ``` ## Ruff Output ```py -x = 123456789 .bit_count() -x = (123456).__abs__() -x = .1.is_integer() -x = 1. .imag -x = 1E+1.imag -x = 1E-1.real -x = 123456789.123456789.hex() -x = 123456789.123456789E123456789 .real -x = 123456789E123456789 .conjugate() -x = 123456789J.real -x = 123456789.123456789J.__add__(0b1011.bit_length()) -x = 0XB1ACC.conjugate() -x = 0B1011 .conjugate() -x = 0O777 .real -x = 0.000000006 .hex() -x = -100.0000J +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign -if 10 .real: - ... +NOT_YET_IMPLEMENTED_StmtIf -y = 100[no] -y = 100(no) +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__beginning_backslash_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__beginning_backslash_py.snap new file mode 100644 index 0000000000..d45080f5bf --- /dev/null +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__beginning_backslash_py.snap @@ -0,0 +1,40 @@ +--- +source: crates/ruff_python_formatter/src/lib.rs +expression: snapshot +input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/beginning_backslash.py +--- +## Input + +```py +\ + + + + + +print("hello, world") +``` + +## Black Differences + +```diff +--- Black ++++ Ruff +@@ -1 +1 @@ +-print("hello, world") ++NOT_YET_IMPLEMENTED_ExprCall +``` + +## Ruff Output + +```py +NOT_YET_IMPLEMENTED_ExprCall +``` + +## Black Output + +```py +print("hello, world") +``` + + diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__bracketmatch_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__bracketmatch_py.snap index 15d5a14567..12e5e46d59 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__bracketmatch_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__bracketmatch_py.snap @@ -19,27 +19,22 @@ lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x ```diff --- Black +++ Ruff -@@ -1,4 +1,6 @@ +@@ -1,4 +1,3 @@ -for ((x in {}) or {})["a"] in x: -+for ((x in {}) or {})['a'] in x: - pass +- pass -pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip()) -lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x -+pem_spam = lambda l, spam = { -+ "x": 3 -+}: not spam.get(l.strip()) -+lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x ++NOT_YET_IMPLEMENTED_StmtFor ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_ExprLambda ``` ## Ruff Output ```py -for ((x in {}) or {})['a'] in x: - pass -pem_spam = lambda l, spam = { - "x": 3 -}: not spam.get(l.strip()) -lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x +NOT_YET_IMPLEMENTED_StmtFor +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_ExprLambda ``` ## Black Output 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 c40c09ee3a..12aa367c1f 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,77 +36,64 @@ class NormalClass ( ```diff --- Black +++ Ruff -@@ -1,16 +1,16 @@ +@@ -1,30 +1,16 @@ -class SimpleClassWithBlankParentheses: -+class SimpleClassWithBlankParentheses(): - pass - +- pass +- ++NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithSpaceParentheses: -+class ClassWithSpaceParentheses ( ): - first_test_data = 90 - second_test_data = 100 -- - def test_func(self): - return None +- first_test_data = 90 +- second_test_data = 100 + +- def test_func(self): +- return None ++NOT_YET_IMPLEMENTED_StmtClassDef - class ClassWithEmptyFunc(object): -+ - def func_with_blank_parentheses(): - return 5 - -@@ -20,11 +20,12 @@ +-class ClassWithEmptyFunc(object): +- def func_with_blank_parentheses(): +- return 5 ++NOT_YET_IMPLEMENTED_StmtClassDef - def class_under_the_func_with_blank_parentheses(): +-def public_func_with_blank_parentheses(): +- return None ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-def class_under_the_func_with_blank_parentheses(): - class InsideFunc: -+ class InsideFunc(): - pass +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef -class NormalClass: -+class NormalClass ( -+): - def func_for_testing(self, first, second): - sum = first + second - return sum +- def func_for_testing(self, first, second): +- sum = first + second +- return sum ++NOT_YET_IMPLEMENTED_StmtClassDef ``` ## Ruff Output ```py -class SimpleClassWithBlankParentheses(): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithSpaceParentheses ( ): - first_test_data = 90 - second_test_data = 100 - def test_func(self): - return None +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithEmptyFunc(object): - - def func_with_blank_parentheses(): - return 5 +NOT_YET_IMPLEMENTED_StmtClassDef -def public_func_with_blank_parentheses(): - return None +NOT_YET_IMPLEMENTED_StmtFunctionDef -def class_under_the_func_with_blank_parentheses(): - class InsideFunc(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -class NormalClass ( -): - def func_for_testing(self, first, second): - sum = first + second - return sum +NOT_YET_IMPLEMENTED_StmtClassDef ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_methods_new_line_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_methods_new_line_py.snap index c569564e5c..ecb8824ed1 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_methods_new_line_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_methods_new_line_py.snap @@ -113,290 +113,259 @@ class ClassWithDecoInitAndVarsAndDocstringWithInner2: ```diff --- Black +++ Ruff -@@ -17,23 +17,19 @@ - - class ClassWithTheDocstringAndInit: - """Just a docstring.""" -- - def __init__(self): - pass +@@ -1,165 +1,61 @@ +-class ClassSimplest: +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef - class ClassWithInitAndVars: - cls_var = 100 -- - def __init__(self): - pass +-class ClassWithSingleField: +- a = 1 ++NOT_YET_IMPLEMENTED_StmtClassDef - class ClassWithInitAndVarsAndDocstring: - """Test class""" -- - cls_var = 100 -- - def __init__(self): - pass - -@@ -46,7 +42,6 @@ - - class ClassWithDecoInitAndVars: - cls_var = 100 -- - @deco - def __init__(self): - pass -@@ -54,9 +49,7 @@ - - class ClassWithDecoInitAndVarsAndDocstring: - """Test class""" -- - cls_var = 100 -- - @deco - def __init__(self): - pass -@@ -70,21 +63,18 @@ - class ClassSimplestWithInnerWithDocstring: - class Inner: - """Just a docstring.""" -- - def __init__(self): - pass +-class ClassWithJustTheDocstring: +- """Just a docstring.""" ++NOT_YET_IMPLEMENTED_StmtClassDef - class ClassWithSingleFieldWithInner: - a = 1 -- - class Inner: - pass +-class ClassWithInit: +- def __init__(self): +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef - class ClassWithJustTheDocstringWithInner: - """Just a docstring.""" -- - class Inner: - pass +-class ClassWithTheDocstringAndInit: +- """Just a docstring.""" ++NOT_YET_IMPLEMENTED_StmtClassDef -@@ -92,29 +82,23 @@ - class ClassWithInitWithInner: - class Inner: - pass -- - def __init__(self): - pass +- def __init__(self): +- pass + ++NOT_YET_IMPLEMENTED_StmtClassDef + +-class ClassWithInitAndVars: +- cls_var = 100 + +- def __init__(self): +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef - class ClassWithInitAndVarsWithInner: - cls_var = 100 -- - class Inner: - pass -- - def __init__(self): - pass +-class ClassWithInitAndVarsAndDocstring: +- """Test class""" ++NOT_YET_IMPLEMENTED_StmtClassDef + +- cls_var = 100 + +- def __init__(self): +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef - class ClassWithInitAndVarsAndDocstringWithInner: - """Test class""" -- - cls_var = 100 -- - class Inner: - pass -- - def __init__(self): - pass +-class ClassWithDecoInit: +- @deco +- def __init__(self): +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef -@@ -122,7 +106,6 @@ - class ClassWithDecoInitWithInner: - class Inner: - pass -- - @deco - def __init__(self): - pass -@@ -130,10 +113,8 @@ - class ClassWithDecoInitAndVarsWithInner: - cls_var = 100 -- - class Inner: - pass -- - @deco - def __init__(self): - pass -@@ -141,12 +122,9 @@ +-class ClassWithDecoInitAndVars: +- cls_var = 100 ++NOT_YET_IMPLEMENTED_StmtClassDef - class ClassWithDecoInitAndVarsAndDocstringWithInner: - """Test class""" -- - cls_var = 100 -- - class Inner: - pass -- - @deco - def __init__(self): - pass -@@ -154,12 +132,9 @@ +- @deco +- def __init__(self): +- pass - class ClassWithDecoInitAndVarsAndDocstringWithInner2: - """Test class""" ++NOT_YET_IMPLEMENTED_StmtClassDef + +-class ClassWithDecoInitAndVarsAndDocstring: +- """Test class""" + +- cls_var = 100 ++NOT_YET_IMPLEMENTED_StmtClassDef + +- @deco +- def __init__(self): +- pass + ++NOT_YET_IMPLEMENTED_StmtClassDef + +-class ClassSimplestWithInner: +- class Inner: +- pass + ++NOT_YET_IMPLEMENTED_StmtClassDef + +-class ClassSimplestWithInnerWithDocstring: +- class Inner: +- """Just a docstring.""" + +- def __init__(self): +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef + + +-class ClassWithSingleFieldWithInner: +- a = 1 ++NOT_YET_IMPLEMENTED_StmtClassDef + +- class Inner: +- pass + ++NOT_YET_IMPLEMENTED_StmtClassDef + +-class ClassWithJustTheDocstringWithInner: +- """Just a docstring.""" + +- class Inner: +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef + + +-class ClassWithInitWithInner: +- class Inner: +- pass - - class Inner: - pass +- def __init__(self): +- pass - - cls_var = 100 - - @deco - def __init__(self): - pass +-class ClassWithInitAndVarsWithInner: +- cls_var = 100 +- +- class Inner: +- pass +- +- def __init__(self): +- pass +- +- +-class ClassWithInitAndVarsAndDocstringWithInner: +- """Test class""" +- +- cls_var = 100 +- +- class Inner: +- pass +- +- def __init__(self): +- pass +- +- +-class ClassWithDecoInitWithInner: +- class Inner: +- pass +- +- @deco +- def __init__(self): +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef + + +-class ClassWithDecoInitAndVarsWithInner: +- cls_var = 100 +- +- class Inner: +- pass +- +- @deco +- def __init__(self): +- pass +- +- +-class ClassWithDecoInitAndVarsAndDocstringWithInner: +- """Test class""" +- +- cls_var = 100 +- +- class Inner: +- pass +- +- @deco +- def __init__(self): +- pass +- +- +-class ClassWithDecoInitAndVarsAndDocstringWithInner2: +- """Test class""" +- +- class Inner: +- pass +- +- cls_var = 100 +- +- @deco +- def __init__(self): +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef ``` ## Ruff Output ```py -class ClassSimplest: - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithSingleField: - a = 1 +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithJustTheDocstring: - """Just a docstring.""" +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithInit: - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithTheDocstringAndInit: - """Just a docstring.""" - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithInitAndVars: - cls_var = 100 - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithInitAndVarsAndDocstring: - """Test class""" - cls_var = 100 - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithDecoInit: - @deco - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithDecoInitAndVars: - cls_var = 100 - @deco - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithDecoInitAndVarsAndDocstring: - """Test class""" - cls_var = 100 - @deco - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassSimplestWithInner: - class Inner: - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassSimplestWithInnerWithDocstring: - class Inner: - """Just a docstring.""" - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithSingleFieldWithInner: - a = 1 - class Inner: - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithJustTheDocstringWithInner: - """Just a docstring.""" - class Inner: - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithInitWithInner: - class Inner: - pass - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithInitAndVarsWithInner: - cls_var = 100 - class Inner: - pass - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithInitAndVarsAndDocstringWithInner: - """Test class""" - cls_var = 100 - class Inner: - pass - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithDecoInitWithInner: - class Inner: - pass - @deco - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithDecoInitAndVarsWithInner: - cls_var = 100 - class Inner: - pass - @deco - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithDecoInitAndVarsAndDocstringWithInner: - """Test class""" - cls_var = 100 - class Inner: - pass - @deco - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithDecoInitAndVarsAndDocstringWithInner2: - """Test class""" - class Inner: - pass - cls_var = 100 - @deco - def __init__(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__collections_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__collections_py.snap index ee2de5b302..f19784f0d6 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__collections_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__collections_py.snap @@ -84,9 +84,31 @@ if True: ```diff --- Black +++ Ruff -@@ -18,44 +18,26 @@ - xyzzy as magic, - ) +@@ -1,99 +1,48 @@ +-import core, time, a ++NOT_YET_IMPLEMENTED_StmtImport + +-from . import A, B, C ++NOT_YET_IMPLEMENTED_StmtImportFrom + + # keeps existing trailing comma +-from foo import ( +- bar, +-) ++NOT_YET_IMPLEMENTED_StmtImportFrom + + # also keeps existing structure +-from foo import ( +- baz, +- qux, +-) ++NOT_YET_IMPLEMENTED_StmtImportFrom + + # `as` works as well +-from foo import ( +- xyzzy as magic, +-) ++NOT_YET_IMPLEMENTED_StmtImportFrom -a = { - 1, @@ -94,15 +116,11 @@ if True: - 3, -} -b = {1, 2, 3} -+a = {1,2,3,} -+b = { -+1,2, -+ 3} - c = { - 1, - 2, - 3, - } +-c = { +- 1, +- 2, +- 3, +-} -x = (1,) -y = (narf(),) -nested = { @@ -116,20 +134,27 @@ if True: - "cccccccccccccccccccccccccccccccccccccccc", - (1, 2, 3), - "dddddddddddddddddddddddddddddddddddddddd", --] ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_ExprDict ++NOT_YET_IMPLEMENTED_ExprDict ++[ ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant ++ % NOT_YET_IMPLEMENTED_ExprTuple, + ] -{ - "oneple": (1,), -} -+x = 1, -+y = narf(), -+nested = {(1,2,3),(4,5,6),} -+nested_no_trailing_comma = {(1,2,3),(4,5,6)} -+nested_long_lines = ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccccccccccccccccccccccc", (1, 2, 3), "dddddddddddddddddddddddddddddddddddddddd"] -+{"oneple": (1,),} - {"oneple": (1,)} +-{"oneple": (1,)} -["ls", "lsoneple/%s" % (foo,)] -+['ls', 'lsoneple/%s' % (foo,)] - x = {"oneple": (1,)} +-x = {"oneple": (1,)} -y = { - "oneple": (1,), -} @@ -137,130 +162,112 @@ if True: - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s" - % bar -) -+y = {"oneple": (1,),} -+assert False, ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s" % bar) ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssert # looping over a 1-tuple should also not get wrapped - for x in (1,): -@@ -63,13 +45,9 @@ - for (x,) in (1,), (2,), (3,): - pass +-for x in (1,): +- pass +-for (x,) in (1,), (2,), (3,): +- pass ++NOT_YET_IMPLEMENTED_StmtFor ++NOT_YET_IMPLEMENTED_StmtFor --[ + [ - 1, - 2, - 3, --] -+[1, 2, 3] ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, + ] -division_result_tuple = (6 / 2,) -+division_result_tuple = (6/2,) - print("foo %r", (foo.bar,)) +-print("foo %r", (foo.bar,)) ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_ExprCall - if True: -@@ -79,21 +57,15 @@ - ) - - if True: -- ec2client.get_waiter("instance_stopped").wait( -+ ec2client.get_waiter('instance_stopped').wait( - InstanceIds=[instance.id], - WaiterConfig={ -- "Delay": 5, -- }, +-if True: +- IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = ( +- Config.IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING +- | {pylons.controllers.WSGIController} - ) -+ 'Delay': 5, -+ }) - ec2client.get_waiter("instance_stopped").wait( - InstanceIds=[instance.id], -- WaiterConfig={ -- "Delay": 5, -- }, -+ WaiterConfig={"Delay": 5,}, - ) - ec2client.get_waiter("instance_stopped").wait( ++NOT_YET_IMPLEMENTED_StmtIf + +-if True: +- ec2client.get_waiter("instance_stopped").wait( - InstanceIds=[instance.id], - WaiterConfig={ - "Delay": 5, - }, -+ InstanceIds=[instance.id], WaiterConfig={"Delay": 5,}, - ) +- ) +- ec2client.get_waiter("instance_stopped").wait( +- InstanceIds=[instance.id], +- WaiterConfig={ +- "Delay": 5, +- }, +- ) +- ec2client.get_waiter("instance_stopped").wait( +- InstanceIds=[instance.id], +- WaiterConfig={ +- "Delay": 5, +- }, +- ) ++NOT_YET_IMPLEMENTED_StmtIf ``` ## Ruff Output ```py -import core, time, a +NOT_YET_IMPLEMENTED_StmtImport -from . import A, B, C +NOT_YET_IMPLEMENTED_StmtImportFrom # keeps existing trailing comma -from foo import ( - bar, -) +NOT_YET_IMPLEMENTED_StmtImportFrom # also keeps existing structure -from foo import ( - baz, - qux, -) +NOT_YET_IMPLEMENTED_StmtImportFrom # `as` works as well -from foo import ( - xyzzy as magic, -) +NOT_YET_IMPLEMENTED_StmtImportFrom -a = {1,2,3,} -b = { -1,2, - 3} -c = { - 1, - 2, - 3, -} -x = 1, -y = narf(), -nested = {(1,2,3),(4,5,6),} -nested_no_trailing_comma = {(1,2,3),(4,5,6)} -nested_long_lines = ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccccccccccccccccccccccc", (1, 2, 3), "dddddddddddddddddddddddddddddddddddddddd"] -{"oneple": (1,),} -{"oneple": (1,)} -['ls', 'lsoneple/%s' % (foo,)] -x = {"oneple": (1,)} -y = {"oneple": (1,),} -assert False, ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s" % bar) +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_ExprDict +NOT_YET_IMPLEMENTED_ExprDict +[ + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant + % NOT_YET_IMPLEMENTED_ExprTuple, +] +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssert # looping over a 1-tuple should also not get wrapped -for x in (1,): - pass -for (x,) in (1,), (2,), (3,): - pass +NOT_YET_IMPLEMENTED_StmtFor +NOT_YET_IMPLEMENTED_StmtFor -[1, 2, 3] +[ + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, +] -division_result_tuple = (6/2,) -print("foo %r", (foo.bar,)) +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_ExprCall -if True: - IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = ( - Config.IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING - | {pylons.controllers.WSGIController} - ) +NOT_YET_IMPLEMENTED_StmtIf -if True: - ec2client.get_waiter('instance_stopped').wait( - InstanceIds=[instance.id], - WaiterConfig={ - 'Delay': 5, - }) - ec2client.get_waiter("instance_stopped").wait( - InstanceIds=[instance.id], - WaiterConfig={"Delay": 5,}, - ) - ec2client.get_waiter("instance_stopped").wait( - InstanceIds=[instance.id], WaiterConfig={"Delay": 5,}, - ) +NOT_YET_IMPLEMENTED_StmtIf ``` ## Black Output 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 5633eef26a..906a936292 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 @@ -22,32 +22,24 @@ def bobtwo(): \ ```diff --- Black +++ Ruff -@@ -1,6 +1,9 @@ +@@ -1,6 +1,4 @@ -def bob(): # pylint: disable=W9016 -+def bob(): \ -+ # pylint: disable=W9016 - pass +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def bobtwo(): # some comment here -+def bobtwo(): \ -+ \ -+ # some comment here - pass +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Ruff Output ```py -def bob(): \ - # pylint: disable=W9016 - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def bobtwo(): \ - \ - # some comment here - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## 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 cd228ca42b..8b8b88686f 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 @@ -178,36 +178,28 @@ instruction()#comment with bad spacing ```diff --- Black +++ Ruff -@@ -1,39 +1,40 @@ - from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( +@@ -1,165 +1,23 @@ +-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( - MyLovelyCompanyTeamProjectComponent, # NOT DRY -+ MyLovelyCompanyTeamProjectComponent # NOT DRY - ) - from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( +-) +-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( - MyLovelyCompanyTeamProjectComponent as component, # DRY -+ MyLovelyCompanyTeamProjectComponent as component # DRY - ) +-) ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImportFrom # Please keep __all__ alphabetized within each category. - __all__ = [ - # Super-special typing primitives. +-__all__ = [ +- # Super-special typing primitives. - "Any", - "Callable", - "ClassVar", -+ 'Any', -+ 'Callable', -+ 'ClassVar', -+ - # ABCs (from collections.abc). +- # ABCs (from collections.abc). - "AbstractSet", # collections.abc.Set. - "ByteString", - "Container", -+ 'AbstractSet', # collections.abc.Set. -+ 'ByteString', -+ 'Container', -+ - # Concrete collection types. +- # Concrete collection types. - "Counter", - "Deque", - "Dict", @@ -217,59 +209,56 @@ instruction()#comment with bad spacing - "FrozenSet", - "NamedTuple", # Not really a type. - "Generator", -+ 'Counter', -+ 'Deque', -+ 'Dict', -+ 'DefaultDict', -+ 'List', -+ 'Set', -+ 'FrozenSet', -+ 'NamedTuple', # Not really a type. -+ 'Generator', - ] +-] ++NOT_YET_IMPLEMENTED_StmtAssign - not_shareables = [ - # singletons - True, - False, +-not_shareables = [ +- # singletons +- True, +- False, - NotImplemented, - ..., -+ NotImplemented, ..., - # builtin types and objects - type, - object, -@@ -48,20 +49,23 @@ - SubBytes(b"spam"), - ] +- # builtin types and objects +- type, +- object, +- object(), +- Exception(), +- 42, +- 100.0, +- "spam", +- # user-defined types and objects +- Cheese, +- Cheese("Wensleydale"), +- SubBytes(b"spam"), +-] ++NOT_YET_IMPLEMENTED_StmtAssign -if "PYTHON" in os.environ: -+if 'PYTHON' in os.environ: - add_compiler(compiler_from_env()) - else: - # for compiler in compilers.values(): +- add_compiler(compiler_from_env()) +-else: +- # for compiler in compilers.values(): - # add_compiler(compiler) -+ # add_compiler(compiler) - add_compiler(compilers[(7.0, 32)]) +- add_compiler(compilers[(7.0, 32)]) - # add_compiler(compilers[(7.1, 64)]) ++NOT_YET_IMPLEMENTED_StmtIf # Comment before function. - def inline_comments_in_brackets_ruin_everything(): - if typedargslist: +-def inline_comments_in_brackets_ruin_everything(): +- if typedargslist: - parameters.children = [children[0], body, children[-1]] # (1 # )1 - parameters.children = [ -+ children[0], # (1 -+ body, -+ children[-1] # )1 -+ ] -+ parameters.children = [ - children[0], - body, - children[-1], # type: ignore -@@ -73,49 +77,42 @@ - parameters.children[-1], # )2 - ] - parameters.children = [parameters.what_if_this_was_actually_long.children[0], body, parameters.children[-1]] # type: ignore +- parameters.children = [ +- children[0], +- body, +- children[-1], # type: ignore +- ] +- else: +- parameters.children = [ +- parameters.children[0], # (2 what if this was actually long +- body, +- parameters.children[-1], # )2 +- ] +- parameters.children = [parameters.what_if_this_was_actually_long.children[0], body, parameters.children[-1]] # type: ignore - if ( - self._proc is not None - # has the child process finished? @@ -278,92 +267,74 @@ instruction()#comment with bad spacing - # transport hasn't been notified yet? - and self._proc.poll() is None - ): -+ if (self._proc is not None -+ # has the child process finished? -+ and self._returncode is None -+ # the child process has finished, but the -+ # transport hasn't been notified yet? -+ and self._proc.poll() is None): - pass - # no newline before or after - short = [ +- pass +- # no newline before or after +- short = [ - # one - 1, - # two - 2, - ] -+ # one -+ 1, -+ # two -+ 2] ++NOT_YET_IMPLEMENTED_StmtFunctionDef - # no newline after +- # no newline after - call( - arg1, - arg2, - """ -+ call(arg1, arg2, """ - short +-short -""", - arg3=True, - ) -+""", arg3=True) - ############################################################################ - - call2( +- ############################################################################ +- +- call2( - # short - arg1, - # but - arg2, - # multiline - """ -+ #short -+ arg1, -+ #but -+ arg2, -+ #multiline -+ """ - short - """, +-short +-""", - # yup - arg3=True, - ) -+ # yup -+ arg3=True) - lcomp = [ +- lcomp = [ - element for element in collection if element is not None # yup # yup # right -+ element # yup -+ for element in collection # yup -+ if element is not None # right - ] - lcomp2 = [ - # hello -@@ -127,7 +124,7 @@ - ] - lcomp3 = [ - # This one is actually too long to fit in a single line. +- ] +- lcomp2 = [ +- # hello +- element +- # yup +- for element in collection +- # right +- if element is not None +- ] +- lcomp3 = [ +- # This one is actually too long to fit in a single line. - element.split("\n", 1)[0] -+ element.split('\n', 1)[0] - # yup - for element in collection.select_elements() - # right -@@ -140,25 +137,23 @@ - # and round and round we go - # and round and round we go +- # yup +- for element in collection.select_elements() +- # right +- if element is not None +- ] +- while True: +- if False: +- continue ++NOT_YET_IMPLEMENTED_StmtAssign # type: Final + +- # and round and round we go +- # and round and round we go - # let's return -+ # let's return - return Node( - syms.simple_stmt, +- return Node( +- syms.simple_stmt, - [Node(statement, result), Leaf(token.NEWLINE, "\n")], # FIXME: \r\n? -+ [ -+ Node(statement, result), -+ Leaf(token.NEWLINE, '\n') # FIXME: \r\n? -+ ], - ) - - +- ) +- +- -CONFIG_FILES = ( - [ - CONFIG_FILE, @@ -371,179 +342,50 @@ instruction()#comment with bad spacing - + SHARED_CONFIG_FILES - + USER_CONFIG_FILES -) # type: Final -+CONFIG_FILES = [CONFIG_FILE, ] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final - - - class Test: - def _init_host(self, parsed) -> None: +- +- +-class Test: +- def _init_host(self, parsed) -> None: - if parsed.hostname is None or not parsed.hostname.strip(): # type: ignore -+ if (parsed.hostname is None or # type: ignore -+ not parsed.hostname.strip()): - pass +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef + ####################### +@@ -167,7 +25,7 @@ + ####################### + + +-instruction() # comment with bad spacing ++NOT_YET_IMPLEMENTED_ExprCall # comment with bad spacing + + # END COMMENTS + # MORE END COMMENTS ``` ## Ruff Output ```py -from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( - MyLovelyCompanyTeamProjectComponent # NOT DRY -) -from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( - MyLovelyCompanyTeamProjectComponent as component # DRY -) +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom # Please keep __all__ alphabetized within each category. -__all__ = [ - # Super-special typing primitives. - 'Any', - 'Callable', - 'ClassVar', +NOT_YET_IMPLEMENTED_StmtAssign - # ABCs (from collections.abc). - 'AbstractSet', # collections.abc.Set. - 'ByteString', - 'Container', +NOT_YET_IMPLEMENTED_StmtAssign - # Concrete collection types. - 'Counter', - 'Deque', - 'Dict', - 'DefaultDict', - 'List', - 'Set', - 'FrozenSet', - 'NamedTuple', # Not really a type. - 'Generator', -] - -not_shareables = [ - # singletons - True, - False, - NotImplemented, ..., - # builtin types and objects - type, - object, - object(), - Exception(), - 42, - 100.0, - "spam", - # user-defined types and objects - Cheese, - Cheese("Wensleydale"), - SubBytes(b"spam"), -] - -if 'PYTHON' in os.environ: - add_compiler(compiler_from_env()) -else: - # for compiler in compilers.values(): - # add_compiler(compiler) - add_compiler(compilers[(7.0, 32)]) +NOT_YET_IMPLEMENTED_StmtIf # Comment before function. -def inline_comments_in_brackets_ruin_everything(): - if typedargslist: - parameters.children = [ - children[0], # (1 - body, - children[-1] # )1 - ] - parameters.children = [ - children[0], - body, - children[-1], # type: ignore - ] - else: - parameters.children = [ - parameters.children[0], # (2 what if this was actually long - body, - parameters.children[-1], # )2 - ] - parameters.children = [parameters.what_if_this_was_actually_long.children[0], body, parameters.children[-1]] # type: ignore - if (self._proc is not None - # has the child process finished? - and self._returncode is None - # the child process has finished, but the - # transport hasn't been notified yet? - and self._proc.poll() is None): - pass - # no newline before or after - short = [ - # one - 1, - # two - 2] - - # no newline after - call(arg1, arg2, """ -short -""", arg3=True) - - ############################################################################ - - call2( - #short - arg1, - #but - arg2, - #multiline - """ -short -""", - # yup - arg3=True) - lcomp = [ - element # yup - for element in collection # yup - if element is not None # right - ] - lcomp2 = [ - # hello - element - # yup - for element in collection - # right - if element is not None - ] - lcomp3 = [ - # This one is actually too long to fit in a single line. - element.split('\n', 1)[0] - # yup - for element in collection.select_elements() - # right - if element is not None - ] - while True: - if False: - continue - - # and round and round we go - # and round and round we go - - # let's return - return Node( - syms.simple_stmt, - [ - Node(statement, result), - Leaf(token.NEWLINE, '\n') # FIXME: \r\n? - ], - ) +NOT_YET_IMPLEMENTED_StmtFunctionDef -CONFIG_FILES = [CONFIG_FILE, ] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final +NOT_YET_IMPLEMENTED_StmtAssign # type: Final -class Test: - def _init_host(self, parsed) -> None: - if (parsed.hostname is None or # type: ignore - not parsed.hostname.strip()): - pass +NOT_YET_IMPLEMENTED_StmtClassDef ####################### @@ -551,7 +393,7 @@ class Test: ####################### -instruction() # comment with bad spacing +NOT_YET_IMPLEMENTED_ExprCall # comment with bad spacing # END COMMENTS # MORE END COMMENTS diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments3_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments3_py.snap new file mode 100644 index 0000000000..d0e6f55613 --- /dev/null +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments3_py.snap @@ -0,0 +1,181 @@ +--- +source: crates/ruff_python_formatter/src/lib.rs +expression: snapshot +input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments3.py +--- +## Input + +```py +# The percent-percent comments are Spyder IDE cells. + + +# %% +def func(): + x = """ + a really long string + """ + lcomp3 = [ + # This one is actually too long to fit in a single line. + element.split("\n", 1)[0] + # yup + for element in collection.select_elements() + # right + if element is not None + ] + # Capture each of the exceptions in the MultiError along with each of their causes and contexts + if isinstance(exc_value, MultiError): + embedded = [] + for exc in exc_value.exceptions: + if exc not in _seen: + embedded.append( + # This should be left alone (before) + traceback.TracebackException.from_exception( + exc, + limit=limit, + lookup_lines=lookup_lines, + capture_locals=capture_locals, + # copy the set of _seen exceptions so that duplicates + # shared between sub-exceptions are not omitted + _seen=set(_seen), + ) + # This should be left alone (after) + ) + + # everything is fine if the expression isn't nested + traceback.TracebackException.from_exception( + exc, + limit=limit, + lookup_lines=lookup_lines, + capture_locals=capture_locals, + # copy the set of _seen exceptions so that duplicates + # shared between sub-exceptions are not omitted + _seen=set(_seen), + ) + + +# %% +``` + +## Black Differences + +```diff +--- Black ++++ Ruff +@@ -2,47 +2,7 @@ + + + # %% +-def func(): +- x = """ +- a really long string +- """ +- lcomp3 = [ +- # This one is actually too long to fit in a single line. +- element.split("\n", 1)[0] +- # yup +- for element in collection.select_elements() +- # right +- if element is not None +- ] +- # Capture each of the exceptions in the MultiError along with each of their causes and contexts +- if isinstance(exc_value, MultiError): +- embedded = [] +- for exc in exc_value.exceptions: +- if exc not in _seen: +- embedded.append( +- # This should be left alone (before) +- traceback.TracebackException.from_exception( +- exc, +- limit=limit, +- lookup_lines=lookup_lines, +- capture_locals=capture_locals, +- # copy the set of _seen exceptions so that duplicates +- # shared between sub-exceptions are not omitted +- _seen=set(_seen), +- ) +- # This should be left alone (after) +- ) +- +- # everything is fine if the expression isn't nested +- traceback.TracebackException.from_exception( +- exc, +- limit=limit, +- lookup_lines=lookup_lines, +- capture_locals=capture_locals, +- # copy the set of _seen exceptions so that duplicates +- # shared between sub-exceptions are not omitted +- _seen=set(_seen), +- ) ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + + # %% +``` + +## Ruff Output + +```py +# The percent-percent comments are Spyder IDE cells. + + +# %% +NOT_YET_IMPLEMENTED_StmtFunctionDef + + +# %% +``` + +## Black Output + +```py +# The percent-percent comments are Spyder IDE cells. + + +# %% +def func(): + x = """ + a really long string + """ + lcomp3 = [ + # This one is actually too long to fit in a single line. + element.split("\n", 1)[0] + # yup + for element in collection.select_elements() + # right + if element is not None + ] + # Capture each of the exceptions in the MultiError along with each of their causes and contexts + if isinstance(exc_value, MultiError): + embedded = [] + for exc in exc_value.exceptions: + if exc not in _seen: + embedded.append( + # This should be left alone (before) + traceback.TracebackException.from_exception( + exc, + limit=limit, + lookup_lines=lookup_lines, + capture_locals=capture_locals, + # copy the set of _seen exceptions so that duplicates + # shared between sub-exceptions are not omitted + _seen=set(_seen), + ) + # This should be left alone (after) + ) + + # everything is fine if the expression isn't nested + traceback.TracebackException.from_exception( + exc, + limit=limit, + lookup_lines=lookup_lines, + capture_locals=capture_locals, + # copy the set of _seen exceptions so that duplicates + # shared between sub-exceptions are not omitted + _seen=set(_seen), + ) + + +# %% +``` + + 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 new file mode 100644 index 0000000000..a4d31f1423 --- /dev/null +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments4_py.snap @@ -0,0 +1,331 @@ +--- +source: crates/ruff_python_formatter/src/lib.rs +expression: snapshot +input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments4.py +--- +## Input + +```py +from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( + MyLovelyCompanyTeamProjectComponent, # NOT DRY +) +from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( + MyLovelyCompanyTeamProjectComponent as component, # DRY +) + + +class C: + @pytest.mark.parametrize( + ("post_data", "message"), + [ + # metadata_version errors. + ( + {}, + "None is an invalid value for Metadata-Version. Error: This field is" + " required. see" + " https://packaging.python.org/specifications/core-metadata", + ), + ( + {"metadata_version": "-1"}, + "'-1' is an invalid value for Metadata-Version. Error: Unknown Metadata" + " Version see" + " https://packaging.python.org/specifications/core-metadata", + ), + # name errors. + ( + {"metadata_version": "1.2"}, + "'' is an invalid value for Name. Error: This field is required. see" + " https://packaging.python.org/specifications/core-metadata", + ), + ( + {"metadata_version": "1.2", "name": "foo-"}, + "'foo-' is an invalid value for Name. Error: Must start and end with a" + " letter or numeral and contain only ascii numeric and '.', '_' and" + " '-'. see https://packaging.python.org/specifications/core-metadata", + ), + # version errors. + ( + {"metadata_version": "1.2", "name": "example"}, + "'' is an invalid value for Version. Error: This field is required. see" + " https://packaging.python.org/specifications/core-metadata", + ), + ( + {"metadata_version": "1.2", "name": "example", "version": "dog"}, + "'dog' is an invalid value for Version. Error: Must start and end with" + " a letter or numeral and contain only ascii numeric and '.', '_' and" + " '-'. see https://packaging.python.org/specifications/core-metadata", + ), + ], + ) + def test_fails_invalid_post_data( + self, pyramid_config, db_request, post_data, message + ): + pyramid_config.testing_securitypolicy(userid=1) + db_request.POST = MultiDict(post_data) + + +def foo(list_a, list_b): + results = ( + User.query.filter(User.foo == "bar") + .filter( # Because foo. + db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b)) + ) + .filter(User.xyz.is_(None)) + # Another comment about the filtering on is_quux goes here. + .filter(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True))) + .order_by(User.created_at.desc()) + .with_for_update(key_share=True) + .all() + ) + return results + + +def foo2(list_a, list_b): + # Standalone comment reasonably placed. + return ( + 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)) + ) + + +def foo3(list_a, list_b): + 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)) + ) +``` + +## Black Differences + +```diff +--- Black ++++ Ruff +@@ -1,94 +1,14 @@ +-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( +- MyLovelyCompanyTeamProjectComponent, # NOT DRY +-) +-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( +- MyLovelyCompanyTeamProjectComponent as component, # DRY +-) ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImportFrom + + +-class C: +- @pytest.mark.parametrize( +- ("post_data", "message"), +- [ +- # metadata_version errors. +- ( +- {}, +- "None is an invalid value for Metadata-Version. Error: This field is" +- " required. see" +- " https://packaging.python.org/specifications/core-metadata", +- ), +- ( +- {"metadata_version": "-1"}, +- "'-1' is an invalid value for Metadata-Version. Error: Unknown Metadata" +- " Version see" +- " https://packaging.python.org/specifications/core-metadata", +- ), +- # name errors. +- ( +- {"metadata_version": "1.2"}, +- "'' is an invalid value for Name. Error: This field is required. see" +- " https://packaging.python.org/specifications/core-metadata", +- ), +- ( +- {"metadata_version": "1.2", "name": "foo-"}, +- "'foo-' is an invalid value for Name. Error: Must start and end with a" +- " letter or numeral and contain only ascii numeric and '.', '_' and" +- " '-'. see https://packaging.python.org/specifications/core-metadata", +- ), +- # version errors. +- ( +- {"metadata_version": "1.2", "name": "example"}, +- "'' is an invalid value for Version. Error: This field is required. see" +- " https://packaging.python.org/specifications/core-metadata", +- ), +- ( +- {"metadata_version": "1.2", "name": "example", "version": "dog"}, +- "'dog' is an invalid value for Version. Error: Must start and end with" +- " a letter or numeral and contain only ascii numeric and '.', '_' and" +- " '-'. see https://packaging.python.org/specifications/core-metadata", +- ), +- ], +- ) +- def test_fails_invalid_post_data( +- self, pyramid_config, db_request, post_data, message +- ): +- pyramid_config.testing_securitypolicy(userid=1) +- db_request.POST = MultiDict(post_data) ++NOT_YET_IMPLEMENTED_StmtClassDef + + +-def foo(list_a, list_b): +- results = ( +- User.query.filter(User.foo == "bar") +- .filter( # Because foo. +- db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b)) +- ) +- .filter(User.xyz.is_(None)) +- # Another comment about the filtering on is_quux goes here. +- .filter(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True))) +- .order_by(User.created_at.desc()) +- .with_for_update(key_share=True) +- .all() +- ) +- return results ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-def foo2(list_a, list_b): +- # Standalone comment reasonably placed. +- return ( +- 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_StmtFunctionDef + + +-def foo3(list_a, list_b): +- 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_StmtFunctionDef +``` + +## Ruff Output + +```py +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom + + +NOT_YET_IMPLEMENTED_StmtClassDef + + +NOT_YET_IMPLEMENTED_StmtFunctionDef + + +NOT_YET_IMPLEMENTED_StmtFunctionDef + + +NOT_YET_IMPLEMENTED_StmtFunctionDef +``` + +## Black Output + +```py +from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( + MyLovelyCompanyTeamProjectComponent, # NOT DRY +) +from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( + MyLovelyCompanyTeamProjectComponent as component, # DRY +) + + +class C: + @pytest.mark.parametrize( + ("post_data", "message"), + [ + # metadata_version errors. + ( + {}, + "None is an invalid value for Metadata-Version. Error: This field is" + " required. see" + " https://packaging.python.org/specifications/core-metadata", + ), + ( + {"metadata_version": "-1"}, + "'-1' is an invalid value for Metadata-Version. Error: Unknown Metadata" + " Version see" + " https://packaging.python.org/specifications/core-metadata", + ), + # name errors. + ( + {"metadata_version": "1.2"}, + "'' is an invalid value for Name. Error: This field is required. see" + " https://packaging.python.org/specifications/core-metadata", + ), + ( + {"metadata_version": "1.2", "name": "foo-"}, + "'foo-' is an invalid value for Name. Error: Must start and end with a" + " letter or numeral and contain only ascii numeric and '.', '_' and" + " '-'. see https://packaging.python.org/specifications/core-metadata", + ), + # version errors. + ( + {"metadata_version": "1.2", "name": "example"}, + "'' is an invalid value for Version. Error: This field is required. see" + " https://packaging.python.org/specifications/core-metadata", + ), + ( + {"metadata_version": "1.2", "name": "example", "version": "dog"}, + "'dog' is an invalid value for Version. Error: Must start and end with" + " a letter or numeral and contain only ascii numeric and '.', '_' and" + " '-'. see https://packaging.python.org/specifications/core-metadata", + ), + ], + ) + def test_fails_invalid_post_data( + self, pyramid_config, db_request, post_data, message + ): + pyramid_config.testing_securitypolicy(userid=1) + db_request.POST = MultiDict(post_data) + + +def foo(list_a, list_b): + results = ( + User.query.filter(User.foo == "bar") + .filter( # Because foo. + db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b)) + ) + .filter(User.xyz.is_(None)) + # Another comment about the filtering on is_quux goes here. + .filter(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True))) + .order_by(User.created_at.desc()) + .with_for_update(key_share=True) + .all() + ) + return results + + +def foo2(list_a, list_b): + # Standalone comment reasonably placed. + return ( + 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)) + ) + + +def foo3(list_a, list_b): + 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)) + ) +``` + + diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments5_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments5_py.snap index f310ae68e4..49eb42254a 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments5_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments5_py.snap @@ -86,91 +86,124 @@ if __name__ == "__main__": ```diff --- Black +++ Ruff -@@ -1,7 +1,6 @@ - while True: - if something.changed: +@@ -1,61 +1,33 @@ +-while True: +- if something.changed: - do.stuff() # trailing comment - # Comment belongs to the `if` block. -+ do.stuff() ++while NOT_YET_IMPLEMENTED_ExprConstant: ++ NOT_YET_IMPLEMENTED_StmtIf # This one belongs to the `while` block. # Should this one, too? I guess so. -@@ -15,7 +14,6 @@ - # then we do this - print(i) + # This one is properly standalone now. + +-for i in range(100): +- # first we do this +- if i % 33 == 0: +- break ++NOT_YET_IMPLEMENTED_StmtFor + +- # then we do this +- print(i) - # and finally we loop around ++NOT_YET_IMPLEMENTED_StmtWith + +-with open(some_temp_file) as f: +- data = f.read() +- +-try: +- with open(some_other_file) as w: +- w.write(data) ++NOT_YET_IMPLEMENTED_StmtTry + +-except OSError: +- print("problems") +- +-import sys ++NOT_YET_IMPLEMENTED_StmtImport + - with open(some_temp_file) as f: - data = f.read() -@@ -33,7 +31,6 @@ # leading function comment - def wat(): - ... +-def wat(): +- ... - # trailing function comment ++NOT_YET_IMPLEMENTED_StmtFunctionDef # SECTION COMMENT + + + # leading 1 +-@deco1 +-# leading 2 +-@deco2(with_args=True) +-# leading 3 +-@deco3 +-def decorated1(): +- ... ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + + # leading 1 +-@deco1 +-# leading 2 +-@deco2(with_args=True) +-# leading function comment +-def decorated1(): +- ... ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + + # Note: this is fixed in +@@ -65,9 +37,7 @@ + + + # This comment should be split from `some_instruction` by two lines but isn't. +-def g(): +- ... ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-if __name__ == "__main__": +- main() ++NOT_YET_IMPLEMENTED_StmtIf ``` ## Ruff Output ```py -while True: - if something.changed: - do.stuff() +while NOT_YET_IMPLEMENTED_ExprConstant: + NOT_YET_IMPLEMENTED_StmtIf # This one belongs to the `while` block. # Should this one, too? I guess so. # This one is properly standalone now. -for i in range(100): - # first we do this - if i % 33 == 0: - break +NOT_YET_IMPLEMENTED_StmtFor - # then we do this - print(i) +NOT_YET_IMPLEMENTED_StmtWith -with open(some_temp_file) as f: - data = f.read() +NOT_YET_IMPLEMENTED_StmtTry -try: - with open(some_other_file) as w: - w.write(data) - -except OSError: - print("problems") - -import sys +NOT_YET_IMPLEMENTED_StmtImport # leading function comment -def wat(): - ... +NOT_YET_IMPLEMENTED_StmtFunctionDef # SECTION COMMENT # leading 1 -@deco1 -# leading 2 -@deco2(with_args=True) -# leading 3 -@deco3 -def decorated1(): - ... +NOT_YET_IMPLEMENTED_StmtFunctionDef # leading 1 -@deco1 -# leading 2 -@deco2(with_args=True) -# leading function comment -def decorated1(): - ... +NOT_YET_IMPLEMENTED_StmtFunctionDef # Note: this is fixed in @@ -180,12 +213,10 @@ some_instruction # This comment should be split from `some_instruction` by two lines but isn't. -def g(): - ... +NOT_YET_IMPLEMENTED_StmtFunctionDef -if __name__ == "__main__": - main() +NOT_YET_IMPLEMENTED_StmtIf ``` ## 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 d0727290f2..509f24610c 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,138 +131,178 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite ```diff --- Black +++ Ruff -@@ -66,7 +66,7 @@ - + element - + another_element - + another_element_with_long_name +@@ -1,118 +1,35 @@ +-from typing import Any, Tuple ++NOT_YET_IMPLEMENTED_StmtImportFrom + + +-def f( +- a, # type: int +-): +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + + # 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 +- +- +-def f( +- a, # type: int +- b, # type: int +- c, # type: int +- d, # type: int +- e, # type: int +- f, # type: int +- g, # type: int +- h, # type: int +- i, # type: int +-): +- # type: (...) -> None +- pass +- +- +-def f( +- arg, # type: int +- *args, # type: *Any +- default=False, # type: bool +- **kwargs, # type: **Any +-): +- # type: (...) -> None +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-def f( +- a, # type: int +- b, # type: int +- c, # type: int +- d, # type: int +-): +- # type: (...) -> None ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +- element = 0 # type: int +- another_element = 1 # type: float +- another_element_with_long_name = 2 # type: int +- another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = ( +- 3 - ) # type: int -+ ) +- an_element_with_a_long_value = calls() or more_calls() and more() # type: bool + +- tup = ( +- another_element, +- another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style, +- ) # type: Tuple[int, int] ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +- a = ( +- element +- + another_element +- + another_element_with_long_name +- + element +- + another_element +- + another_element_with_long_name +- ) # type: int + ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +-def f( +- x, # not a type comment +- y, # type: int +-): +- # type: (...) -> None +- pass + ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +-def f( +- x, # not a type comment +-): # type: (int) -> None +- pass + ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +-def func( +- a=some_list[0], # type: int +-): # type: () -> int +- c = call( +- 0.0123, +- 0.0456, +- 0.0789, +- 0.0123, +- 0.0456, +- 0.0789, +- 0.0123, +- 0.0456, +- 0.0789, +- a[-1], # type: ignore +- ) + +- c = call( +- "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore +- ) ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def f( +-result = ( # aaa +- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +-) ++NOT_YET_IMPLEMENTED_StmtAssign + +-AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore ++NOT_YET_IMPLEMENTED_StmtAssign # type: ignore + +-call_to_some_function_asdf( +- foo, +- [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore +-) ++NOT_YET_IMPLEMENTED_ExprCall + +-aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] ++NOT_YET_IMPLEMENTED_StmtAssign # type: ignore[arg-type] ``` ## Ruff Output ```py -from typing import Any, Tuple +NOT_YET_IMPLEMENTED_StmtImportFrom -def f( - a, # type: int -): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef # 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_StmtFunctionDef -def f( - a, # type: int - b, # type: int - c, # type: int - d, # type: int - e, # type: int - f, # type: int - g, # type: int - h, # type: int - i, # type: int -): - # type: (...) -> None - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def f( - arg, # type: int - *args, # type: *Any - default=False, # type: bool - **kwargs, # type: **Any -): - # type: (...) -> None - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def f( - a, # type: int - b, # type: int - c, # type: int - d, # type: int -): - # type: (...) -> None - - element = 0 # type: int - another_element = 1 # type: float - another_element_with_long_name = 2 # type: int - another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = ( - 3 - ) # type: int - an_element_with_a_long_value = calls() or more_calls() and more() # type: bool - - tup = ( - another_element, - another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style, - ) # type: Tuple[int, int] - - a = ( - element - + another_element - + another_element_with_long_name - + element - + another_element - + another_element_with_long_name - ) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def f( - x, # not a type comment - y, # type: int -): - # type: (...) -> None - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def f( - x, # not a type comment -): # type: (int) -> None - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def func( - a=some_list[0], # type: int -): # type: () -> int - c = call( - 0.0123, - 0.0456, - 0.0789, - 0.0123, - 0.0456, - 0.0789, - 0.0123, - 0.0456, - 0.0789, - a[-1], # type: ignore - ) - - c = call( - "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore - ) +NOT_YET_IMPLEMENTED_StmtFunctionDef -result = ( # aaa - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -) +NOT_YET_IMPLEMENTED_StmtAssign -AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore +NOT_YET_IMPLEMENTED_StmtAssign # type: ignore -call_to_some_function_asdf( - foo, - [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore -) +NOT_YET_IMPLEMENTED_ExprCall -aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] +NOT_YET_IMPLEMENTED_StmtAssign # type: ignore[arg-type] ``` ## Black Output 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 97ea9a42fb..6b73d2f41d 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,60 +152,195 @@ def bar(): ```diff --- Black +++ Ruff -@@ -35,9 +35,10 @@ +@@ -1,161 +1,90 @@ + # Test for https://github.com/psf/black/issues/246. + +-some = statement ++NOT_YET_IMPLEMENTED_StmtAssign - some = statement --# This should be stick to the statement above + # This comment should be split from the statement above by two lines. +-def function(): +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef -+# This should be stick to the statement above +-some = statement ++NOT_YET_IMPLEMENTED_StmtAssign + + + # This multiline comments section + # should be split from the statement + # above by two lines. +-def function(): +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-some = statement ++NOT_YET_IMPLEMENTED_StmtAssign + + + # This comment should be split from the statement above by two lines. +-async def async_function(): +- pass ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef + + +-some = statement ++NOT_YET_IMPLEMENTED_StmtAssign + + + # This comment should be split from the statement above by two lines. +-class MyClass: +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef + ++ ++NOT_YET_IMPLEMENTED_StmtAssign + + +-some = statement + # This should be stick to the statement above + +- # This should be split from the above by two lines - class MyClassWithComplexLeadingComments: - pass -@@ -102,11 +103,9 @@ - # Leading comment before inline function - def inline(): - pass +-class MyClassWithComplexLeadingComments: +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef + + +-class ClassWithDocstring: +- """A docstring.""" ++NOT_YET_IMPLEMENTED_StmtClassDef + + + # Leading comment after a class with just a docstring +-class MyClassAfterAnotherClassWithDocstring: +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef + + +-some = statement ++NOT_YET_IMPLEMENTED_StmtAssign + + + # leading 1 +-@deco1 +-# leading 2 +-# leading 2 extra +-@deco2(with_args=True) +-# leading 3 +-@deco3 +-# leading 4 +-def decorated(): +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-some = statement ++NOT_YET_IMPLEMENTED_StmtAssign + + + # leading 1 +-@deco1 +-# leading 2 +-@deco2(with_args=True) - - # Another leading comment - def another_inline(): - pass +-# leading 3 that already has an empty line +-@deco3 +-# leading 4 +-def decorated_with_split_leading_comments(): +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-some = statement ++NOT_YET_IMPLEMENTED_StmtAssign + + + # leading 1 +-@deco1 +-# leading 2 +-@deco2(with_args=True) +-# leading 3 +-@deco3 - - else: - # More leading comments - def inline_after_else(): -@@ -117,11 +116,9 @@ - # Leading comment before "top-level inline" function - def top_level_quote_inline(): - pass +-# leading 4 that already has an empty line +-def decorated_with_split_leading_comments(): +- pass - - # Another leading comment - def another_top_level_quote_inline_inline(): - pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +-def main(): +- if a: +- # Leading comment before inline function +- def inline(): +- pass + +- # Another leading comment +- def another_inline(): +- pass - - else: - # More leading comments - def top_level_quote_inline_after_else(): -@@ -138,7 +135,6 @@ +- else: +- # More leading comments +- def inline_after_else(): +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-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(): +- pass +- +- +-class MyClass: +- # First method has no empty lines between bare class def. +- # More comments. +- def first_method(self): +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef + + # Regression test for https://github.com/psf/black/issues/3454. - def foo(): - pass +-def foo(): +- pass - # Trailing comment that belongs to this function ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-@decorator1 +-@decorator2 # fmt: skip +-def bar(): +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef - @decorator1 -@@ -150,9 +146,6 @@ # Regression test for https://github.com/psf/black/issues/3454. - def foo(): - pass +-def foo(): +- 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. ++NOT_YET_IMPLEMENTED_StmtFunctionDef - @decorator1 +-@decorator1 +-# A standalone comment +-def bar(): +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Ruff Output @@ -213,158 +348,94 @@ def bar(): ```py # Test for https://github.com/psf/black/issues/246. -some = statement +NOT_YET_IMPLEMENTED_StmtAssign # This comment should be split from the statement above by two lines. -def function(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -some = statement +NOT_YET_IMPLEMENTED_StmtAssign # This multiline comments section # should be split from the statement # above by two lines. -def function(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -some = statement +NOT_YET_IMPLEMENTED_StmtAssign # This comment should be split from the statement above by two lines. -async def async_function(): - pass +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -some = statement +NOT_YET_IMPLEMENTED_StmtAssign # This comment should be split from the statement above by two lines. -class MyClass: - pass +NOT_YET_IMPLEMENTED_StmtClassDef -some = statement +NOT_YET_IMPLEMENTED_StmtAssign # This should be stick to the statement above # This should be split from the above by two lines -class MyClassWithComplexLeadingComments: - pass +NOT_YET_IMPLEMENTED_StmtClassDef -class ClassWithDocstring: - """A docstring.""" +NOT_YET_IMPLEMENTED_StmtClassDef # Leading comment after a class with just a docstring -class MyClassAfterAnotherClassWithDocstring: - pass +NOT_YET_IMPLEMENTED_StmtClassDef -some = statement +NOT_YET_IMPLEMENTED_StmtAssign # leading 1 -@deco1 -# leading 2 -# leading 2 extra -@deco2(with_args=True) -# leading 3 -@deco3 -# leading 4 -def decorated(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -some = statement +NOT_YET_IMPLEMENTED_StmtAssign # leading 1 -@deco1 -# leading 2 -@deco2(with_args=True) - -# leading 3 that already has an empty line -@deco3 -# leading 4 -def decorated_with_split_leading_comments(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -some = statement +NOT_YET_IMPLEMENTED_StmtAssign # leading 1 -@deco1 -# leading 2 -@deco2(with_args=True) -# leading 3 -@deco3 - -# leading 4 that already has an empty line -def decorated_with_split_leading_comments(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def main(): - if a: - # Leading comment before inline function - def inline(): - pass - # Another leading comment - def another_inline(): - pass - else: - # More leading comments - def inline_after_else(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -if a: - # Leading comment before "top-level inline" function - def top_level_quote_inline(): - pass - # Another leading comment - def another_top_level_quote_inline_inline(): - pass -else: - # More leading comments - def top_level_quote_inline_after_else(): - pass +NOT_YET_IMPLEMENTED_StmtIf -class MyClass: - # First method has no empty lines between bare class def. - # More comments. - def first_method(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef # Regression test for https://github.com/psf/black/issues/3454. -def foo(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -@decorator1 -@decorator2 # fmt: skip -def bar(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef # Regression test for https://github.com/psf/black/issues/3454. -def foo(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -@decorator1 -# A standalone comment -def bar(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## 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 3709a25f65..ffa63a0b94 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 @@ -32,63 +32,53 @@ def function(a:int=42): ```diff --- Black +++ Ruff -@@ -1,23 +1,20 @@ +@@ -1,23 +1,11 @@ -from .config import ( - ConfigTypeAttributes, - Int, - Path, # String, - # DEFAULT_TYPE_ATTRIBUTES, -+from .config import ( ConfigTypeAttributes, Int, Path, # String, -+ # DEFAULT_TYPE_ATTRIBUTES, - ) +-) ++NOT_YET_IMPLEMENTED_StmtImportFrom - result = 1 # A simple comment +-result = 1 # A simple comment -result = (1,) # Another one -+result = ( 1, ) # Another one ++NOT_YET_IMPLEMENTED_StmtAssign # A simple comment ++NOT_YET_IMPLEMENTED_StmtAssign # Another one - result = 1 #  type: ignore - result = 1 # This comment is talking about type: ignore - square = Square(4) #  type: Optional[Square] +-result = 1 #  type: ignore +-result = 1 # This comment is talking about type: ignore +-square = Square(4) #  type: Optional[Square] ++NOT_YET_IMPLEMENTED_StmtAssign #  type: ignore ++NOT_YET_IMPLEMENTED_StmtAssign # This comment is talking about type: ignore ++NOT_YET_IMPLEMENTED_StmtAssign #  type: Optional[Square] -def function(a: int = 42): - """This docstring is already formatted - a - b -+def function(a:int=42): -+ """ This docstring is already formatted -+ a -+ b - """ +- """ - # There's a NBSP + 3 spaces before -+ #  There's a NBSP + 3 spaces before - # And 4 spaces on the next line - pass +- # And 4 spaces on the next line +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Ruff Output ```py -from .config import ( ConfigTypeAttributes, Int, Path, # String, - # DEFAULT_TYPE_ATTRIBUTES, -) +NOT_YET_IMPLEMENTED_StmtImportFrom -result = 1 # A simple comment -result = ( 1, ) # Another one +NOT_YET_IMPLEMENTED_StmtAssign # A simple comment +NOT_YET_IMPLEMENTED_StmtAssign # Another one -result = 1 #  type: ignore -result = 1 # This comment is talking about type: ignore -square = Square(4) #  type: Optional[Square] +NOT_YET_IMPLEMENTED_StmtAssign #  type: ignore +NOT_YET_IMPLEMENTED_StmtAssign # This comment is talking about type: ignore +NOT_YET_IMPLEMENTED_StmtAssign #  type: Optional[Square] -def function(a:int=42): - """ This docstring is already formatted - a - b - """ - #  There's a NBSP + 3 spaces before - # And 4 spaces on the next line - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## 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 58017bff25..c4d6655974 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 @@ -109,31 +109,107 @@ async def wat(): ```diff --- Black +++ Ruff -@@ -4,10 +4,12 @@ +@@ -4,93 +4,42 @@ # # Has many lines. Many, many lines. # Many, many, many lines. -"""Module docstring. -+( -+ """Module docstring. ++NOT_YET_IMPLEMENTED_ExprConstant - Possibly also many, many lines. - """ -+) +-Possibly also many, many lines. +-""" ++NOT_YET_IMPLEMENTED_StmtImport ++NOT_YET_IMPLEMENTED_StmtImport - import os.path - import sys -@@ -19,9 +21,6 @@ - import fast - except ImportError: - import slow as fast +-import os.path +-import sys +- +-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 - - -# Some comment before a function. - y = 1 +-y = 1 ++NOT_YET_IMPLEMENTED_StmtTry ++NOT_YET_IMPLEMENTED_StmtAssign ( # some strings -@@ -93,4 +92,4 @@ + y # type: ignore + ) +- + +-def function(default=None): +- """Docstring comes first. + +- Possibly many lines. +- """ +- # FIXME: Some comment about why this function is crap but still in production. +- import inner_imports +- +- if inner_imports.are_evil(): +- # Explains why we have this if. +- # In great detail indeed. +- x = X() +- return x.method1() # type: ignore +- +- # This return is also commented for some reason. +- return default ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + + # Explains why we use global state. +-GLOBAL_STATE = {"a": a(1), "b": a(2), "c": a(3)} ++NOT_YET_IMPLEMENTED_StmtAssign + + + # Another comment! + # This time two lines. +- + +-class Foo: +- """Docstring for class Foo. Example from Sphinx docs.""" + +- #: 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 +- """Docstring for class attribute Foo.baz.""" +- +- def __init__(self): +- #: Doc comment for instance attribute qux. +- self.qux = 3 +- +- self.spam = 4 +- """Docstring for instance attribute spam.""" ++NOT_YET_IMPLEMENTED_StmtClassDef + + + #'

This is pweave!

+ + +-@fast(really=True) +-async def wat(): +- # This comment, for some reason \ +- # contains a trailing backslash. +- async with X.open_async() as x: # Some more comments +- result = await x.method1() +- # Comment after ending a block. +- if result: +- print("A OK", file=sys.stdout) +- # Comment between things. +- print() ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef + # Some closing comments. # Maybe Vim or Emacs directives for formatting. @@ -151,90 +227,40 @@ async def wat(): # # Has many lines. Many, many lines. # Many, many, many lines. -( - """Module docstring. +NOT_YET_IMPLEMENTED_ExprConstant -Possibly also many, many lines. -""" -) +NOT_YET_IMPLEMENTED_StmtImport +NOT_YET_IMPLEMENTED_StmtImport -import os.path -import sys +NOT_YET_IMPLEMENTED_StmtImport +NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment -import a -from b.c import X # some noqa comment - -try: - import fast -except ImportError: - import slow as fast -y = 1 +NOT_YET_IMPLEMENTED_StmtTry +NOT_YET_IMPLEMENTED_StmtAssign ( # some strings y # type: ignore ) -def function(default=None): - """Docstring comes first. - - Possibly many lines. - """ - # FIXME: Some comment about why this function is crap but still in production. - import inner_imports - - if inner_imports.are_evil(): - # Explains why we have this if. - # In great detail indeed. - x = X() - return x.method1() # type: ignore - - # This return is also commented for some reason. - return default +NOT_YET_IMPLEMENTED_StmtFunctionDef # Explains why we use global state. -GLOBAL_STATE = {"a": a(1), "b": a(2), "c": a(3)} +NOT_YET_IMPLEMENTED_StmtAssign # Another comment! # This time two lines. -class Foo: - """Docstring for class Foo. Example from Sphinx docs.""" - - #: 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 - """Docstring for class attribute Foo.baz.""" - - def __init__(self): - #: Doc comment for instance attribute qux. - self.qux = 3 - - self.spam = 4 - """Docstring for instance attribute spam.""" +NOT_YET_IMPLEMENTED_StmtClassDef #'

This is pweave!

-@fast(really=True) -async def wat(): - # This comment, for some reason \ - # contains a trailing backslash. - async with X.open_async() as x: # Some more comments - result = await x.method1() - # Comment after ending a block. - if result: - print("A OK", file=sys.stdout) - # Comment between things. - print() +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Some closing comments. diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_no_trailing_comma_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_no_trailing_comma_py.snap index 439ada0979..b45f26eec3 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_no_trailing_comma_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_no_trailing_comma_py.snap @@ -194,272 +194,195 @@ class C: ```diff --- Black +++ Ruff -@@ -34,7 +34,7 @@ - xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy( - push_manager=context.request.resource_manager, - max_items_to_push=num_items, +@@ -1,181 +1 @@ +-class C: +- def test(self) -> None: +- with patch("black.out", print): +- self.assertEqual( +- unstyle(str(report)), "1 file reformatted, 1 file failed to reformat." +- ) +- self.assertEqual( +- unstyle(str(report)), +- "1 file reformatted, 1 file left unchanged, 1 file failed to reformat.", +- ) +- self.assertEqual( +- unstyle(str(report)), +- "2 files reformatted, 1 file left unchanged, 1 file failed to" +- " reformat.", +- ) +- self.assertEqual( +- unstyle(str(report)), +- "2 files reformatted, 2 files left unchanged, 2 files failed to" +- " reformat.", +- ) +- for i in (a,): +- if ( +- # Rule 1 +- i % 2 == 0 +- # Rule 2 +- and i % 3 == 0 +- ): +- while ( +- # Just a comment +- call() +- # Another +- ): +- print(i) +- xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy( +- push_manager=context.request.resource_manager, +- max_items_to_push=num_items, - batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE, -+ batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE - ).push( - # Only send the first n items. - items=items[:num_items] -@@ -68,7 +68,7 @@ - key6: value6, - key7: value7, - key8: value8, +- ).push( +- # Only send the first n items. +- items=items[:num_items] +- ) +- return ( +- 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s' +- % (test.name, test.filename, lineno, lname, err) +- ) +- +- def omitting_trailers(self) -> None: +- get_collection( +- hey_this_is_a_very_long_call, it_has_funny_attributes, really=True +- )[OneLevelIndex] +- get_collection( +- hey_this_is_a_very_long_call, it_has_funny_attributes, really=True +- )[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex] +- d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][ +- 22 +- ] +- assignment = ( +- some.rather.elaborate.rule() and another.rule.ending_with.index[123] +- ) +- +- def easy_asserts(self) -> None: +- assert { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, - key9: value9, -+ key9: value9 - } == expected, "Not what we expected" - - assert expected == { -@@ -80,7 +80,7 @@ - key6: value6, - key7: value7, - key8: value8, +- } == expected, "Not what we expected" +- +- assert expected == { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, - key9: value9, -+ key9: value9 - }, "Not what we expected" - - assert expected == { -@@ -92,7 +92,7 @@ - key6: value6, - key7: value7, - key8: value8, +- }, "Not what we expected" +- +- assert expected == { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, - key9: value9, -+ key9: value9 - } - - def tricky_asserts(self) -> None: -@@ -105,7 +105,7 @@ - key6: value6, - key7: value7, - key8: value8, +- } +- +- def tricky_asserts(self) -> None: +- assert { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, - key9: value9, -+ key9: value9 - } == expected( - value, is_going_to_be="too long to fit in a single line", srsly=True - ), "Not what we expected" -@@ -119,7 +119,7 @@ - key6: value6, - key7: value7, - key8: value8, +- } == expected( +- value, is_going_to_be="too long to fit in a single line", srsly=True +- ), "Not what we expected" +- +- assert { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, - key9: value9, -+ key9: value9 - } == expected, ( - "Not what we expected and the message is too long to fit in one line" - ) -@@ -135,7 +135,7 @@ - key6: value6, - key7: value7, - key8: value8, +- } == expected, ( +- "Not what we expected and the message is too long to fit in one line" +- ) +- +- assert expected( +- value, is_going_to_be="too long to fit in a single line", srsly=True +- ) == { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, - key9: value9, -+ key9: value9 - }, "Not what we expected" - - assert expected == { -@@ -147,7 +147,7 @@ - key6: value6, - key7: value7, - key8: value8, +- }, "Not what we expected" +- +- assert expected == { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, - key9: value9, -+ key9: value9 - }, ( - "Not what we expected and the message is too long to fit in one line" - " because it's too long" -@@ -176,6 +176,6 @@ - key6: value6, - key7: value7, - key8: value8, +- }, ( +- "Not what we expected and the message is too long to fit in one line" +- " because it's too long" +- ) +- +- dis_c_instance_method = """\ +- %3d 0 LOAD_FAST 1 (x) +- 2 LOAD_CONST 1 (1) +- 4 COMPARE_OP 2 (==) +- 6 LOAD_FAST 0 (self) +- 8 STORE_ATTR 0 (x) +- 10 LOAD_CONST 0 (None) +- 12 RETURN_VALUE +- """ % ( +- _C.__init__.__code__.co_firstlineno + 1, +- ) +- +- assert ( +- expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect +- == { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, - key9: value9, -+ key9: value9 - } - ) +- } +- ) ++NOT_YET_IMPLEMENTED_StmtClassDef ``` ## Ruff Output ```py -class C: - def test(self) -> None: - with patch("black.out", print): - self.assertEqual( - unstyle(str(report)), "1 file reformatted, 1 file failed to reformat." - ) - self.assertEqual( - unstyle(str(report)), - "1 file reformatted, 1 file left unchanged, 1 file failed to reformat.", - ) - self.assertEqual( - unstyle(str(report)), - "2 files reformatted, 1 file left unchanged, 1 file failed to" - " reformat.", - ) - self.assertEqual( - unstyle(str(report)), - "2 files reformatted, 2 files left unchanged, 2 files failed to" - " reformat.", - ) - for i in (a,): - if ( - # Rule 1 - i % 2 == 0 - # Rule 2 - and i % 3 == 0 - ): - while ( - # Just a comment - call() - # Another - ): - print(i) - xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy( - push_manager=context.request.resource_manager, - max_items_to_push=num_items, - batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE - ).push( - # Only send the first n items. - items=items[:num_items] - ) - return ( - 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s' - % (test.name, test.filename, lineno, lname, err) - ) - - def omitting_trailers(self) -> None: - get_collection( - hey_this_is_a_very_long_call, it_has_funny_attributes, really=True - )[OneLevelIndex] - get_collection( - hey_this_is_a_very_long_call, it_has_funny_attributes, really=True - )[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex] - d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][ - 22 - ] - assignment = ( - some.rather.elaborate.rule() and another.rule.ending_with.index[123] - ) - - def easy_asserts(self) -> None: - assert { - key1: value1, - key2: value2, - key3: value3, - key4: value4, - key5: value5, - key6: value6, - key7: value7, - key8: value8, - key9: value9 - } == expected, "Not what we expected" - - assert expected == { - key1: value1, - key2: value2, - key3: value3, - key4: value4, - key5: value5, - key6: value6, - key7: value7, - key8: value8, - key9: value9 - }, "Not what we expected" - - assert expected == { - key1: value1, - key2: value2, - key3: value3, - key4: value4, - key5: value5, - key6: value6, - key7: value7, - key8: value8, - key9: value9 - } - - def tricky_asserts(self) -> None: - assert { - key1: value1, - key2: value2, - key3: value3, - key4: value4, - key5: value5, - key6: value6, - key7: value7, - key8: value8, - key9: value9 - } == expected( - value, is_going_to_be="too long to fit in a single line", srsly=True - ), "Not what we expected" - - assert { - key1: value1, - key2: value2, - key3: value3, - key4: value4, - key5: value5, - key6: value6, - key7: value7, - key8: value8, - key9: value9 - } == expected, ( - "Not what we expected and the message is too long to fit in one line" - ) - - assert expected( - value, is_going_to_be="too long to fit in a single line", srsly=True - ) == { - key1: value1, - key2: value2, - key3: value3, - key4: value4, - key5: value5, - key6: value6, - key7: value7, - key8: value8, - key9: value9 - }, "Not what we expected" - - assert expected == { - key1: value1, - key2: value2, - key3: value3, - key4: value4, - key5: value5, - key6: value6, - key7: value7, - key8: value8, - key9: value9 - }, ( - "Not what we expected and the message is too long to fit in one line" - " because it's too long" - ) - - dis_c_instance_method = """\ - %3d 0 LOAD_FAST 1 (x) - 2 LOAD_CONST 1 (1) - 4 COMPARE_OP 2 (==) - 6 LOAD_FAST 0 (self) - 8 STORE_ATTR 0 (x) - 10 LOAD_CONST 0 (None) - 12 RETURN_VALUE - """ % ( - _C.__init__.__code__.co_firstlineno + 1, - ) - - assert ( - expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect - == { - key1: value1, - key2: value2, - key3: value3, - key4: value4, - key5: value5, - key6: value6, - key7: value7, - key8: value8, - key9: value9 - } - ) +NOT_YET_IMPLEMENTED_StmtClassDef ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_py.snap new file mode 100644 index 0000000000..86812da5ea --- /dev/null +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_py.snap @@ -0,0 +1,574 @@ +--- +source: crates/ruff_python_formatter/src/lib.rs +expression: snapshot +input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition.py +--- +## Input + +```py +class C: + def test(self) -> None: + with patch("black.out", print): + self.assertEqual( + unstyle(str(report)), "1 file reformatted, 1 file failed to reformat." + ) + self.assertEqual( + unstyle(str(report)), + "1 file reformatted, 1 file left unchanged, 1 file failed to reformat.", + ) + self.assertEqual( + unstyle(str(report)), + "2 files reformatted, 1 file left unchanged, 1 file failed to" + " reformat.", + ) + self.assertEqual( + unstyle(str(report)), + "2 files reformatted, 2 files left unchanged, 2 files failed to" + " reformat.", + ) + for i in (a,): + if ( + # Rule 1 + i % 2 == 0 + # Rule 2 + and i % 3 == 0 + ): + while ( + # Just a comment + call() + # Another + ): + print(i) + xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy( + push_manager=context.request.resource_manager, + max_items_to_push=num_items, + batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE, + ).push( + # Only send the first n items. + items=items[:num_items] + ) + return ( + 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s' + % (test.name, test.filename, lineno, lname, err) + ) + + def omitting_trailers(self) -> None: + get_collection( + hey_this_is_a_very_long_call, it_has_funny_attributes, really=True + )[OneLevelIndex] + get_collection( + hey_this_is_a_very_long_call, it_has_funny_attributes, really=True + )[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex] + d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][ + 22 + ] + assignment = ( + some.rather.elaborate.rule() and another.rule.ending_with.index[123] + ) + + def easy_asserts(self) -> None: + assert { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + } == expected, "Not what we expected" + + assert expected == { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + }, "Not what we expected" + + assert expected == { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + } + + def tricky_asserts(self) -> None: + assert { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + } == expected( + value, is_going_to_be="too long to fit in a single line", srsly=True + ), "Not what we expected" + + assert { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + } == expected, ( + "Not what we expected and the message is too long to fit in one line" + ) + + assert expected( + value, is_going_to_be="too long to fit in a single line", srsly=True + ) == { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + }, "Not what we expected" + + assert expected == { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + }, ( + "Not what we expected and the message is too long to fit in one line" + " because it's too long" + ) + + dis_c_instance_method = """\ + %3d 0 LOAD_FAST 1 (x) + 2 LOAD_CONST 1 (1) + 4 COMPARE_OP 2 (==) + 6 LOAD_FAST 0 (self) + 8 STORE_ATTR 0 (x) + 10 LOAD_CONST 0 (None) + 12 RETURN_VALUE + """ % ( + _C.__init__.__code__.co_firstlineno + 1, + ) + + assert ( + expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect + == { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + } + ) +``` + +## Black Differences + +```diff +--- Black ++++ Ruff +@@ -1,181 +1 @@ +-class C: +- def test(self) -> None: +- with patch("black.out", print): +- self.assertEqual( +- unstyle(str(report)), "1 file reformatted, 1 file failed to reformat." +- ) +- self.assertEqual( +- unstyle(str(report)), +- "1 file reformatted, 1 file left unchanged, 1 file failed to reformat.", +- ) +- self.assertEqual( +- unstyle(str(report)), +- "2 files reformatted, 1 file left unchanged, 1 file failed to" +- " reformat.", +- ) +- self.assertEqual( +- unstyle(str(report)), +- "2 files reformatted, 2 files left unchanged, 2 files failed to" +- " reformat.", +- ) +- for i in (a,): +- if ( +- # Rule 1 +- i % 2 == 0 +- # Rule 2 +- and i % 3 == 0 +- ): +- while ( +- # Just a comment +- call() +- # Another +- ): +- print(i) +- xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy( +- push_manager=context.request.resource_manager, +- max_items_to_push=num_items, +- batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE, +- ).push( +- # Only send the first n items. +- items=items[:num_items] +- ) +- return ( +- 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s' +- % (test.name, test.filename, lineno, lname, err) +- ) +- +- def omitting_trailers(self) -> None: +- get_collection( +- hey_this_is_a_very_long_call, it_has_funny_attributes, really=True +- )[OneLevelIndex] +- get_collection( +- hey_this_is_a_very_long_call, it_has_funny_attributes, really=True +- )[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex] +- d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][ +- 22 +- ] +- assignment = ( +- some.rather.elaborate.rule() and another.rule.ending_with.index[123] +- ) +- +- def easy_asserts(self) -> None: +- assert { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, +- key9: value9, +- } == expected, "Not what we expected" +- +- assert expected == { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, +- key9: value9, +- }, "Not what we expected" +- +- assert expected == { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, +- key9: value9, +- } +- +- def tricky_asserts(self) -> None: +- assert { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, +- key9: value9, +- } == expected( +- value, is_going_to_be="too long to fit in a single line", srsly=True +- ), "Not what we expected" +- +- assert { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, +- key9: value9, +- } == expected, ( +- "Not what we expected and the message is too long to fit in one line" +- ) +- +- assert expected( +- value, is_going_to_be="too long to fit in a single line", srsly=True +- ) == { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, +- key9: value9, +- }, "Not what we expected" +- +- assert expected == { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, +- key9: value9, +- }, ( +- "Not what we expected and the message is too long to fit in one line" +- " because it's too long" +- ) +- +- dis_c_instance_method = """\ +- %3d 0 LOAD_FAST 1 (x) +- 2 LOAD_CONST 1 (1) +- 4 COMPARE_OP 2 (==) +- 6 LOAD_FAST 0 (self) +- 8 STORE_ATTR 0 (x) +- 10 LOAD_CONST 0 (None) +- 12 RETURN_VALUE +- """ % ( +- _C.__init__.__code__.co_firstlineno + 1, +- ) +- +- assert ( +- expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect +- == { +- key1: value1, +- key2: value2, +- key3: value3, +- key4: value4, +- key5: value5, +- key6: value6, +- key7: value7, +- key8: value8, +- key9: value9, +- } +- ) ++NOT_YET_IMPLEMENTED_StmtClassDef +``` + +## Ruff Output + +```py +NOT_YET_IMPLEMENTED_StmtClassDef +``` + +## Black Output + +```py +class C: + def test(self) -> None: + with patch("black.out", print): + self.assertEqual( + unstyle(str(report)), "1 file reformatted, 1 file failed to reformat." + ) + self.assertEqual( + unstyle(str(report)), + "1 file reformatted, 1 file left unchanged, 1 file failed to reformat.", + ) + self.assertEqual( + unstyle(str(report)), + "2 files reformatted, 1 file left unchanged, 1 file failed to" + " reformat.", + ) + self.assertEqual( + unstyle(str(report)), + "2 files reformatted, 2 files left unchanged, 2 files failed to" + " reformat.", + ) + for i in (a,): + if ( + # Rule 1 + i % 2 == 0 + # Rule 2 + and i % 3 == 0 + ): + while ( + # Just a comment + call() + # Another + ): + print(i) + xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy( + push_manager=context.request.resource_manager, + max_items_to_push=num_items, + batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE, + ).push( + # Only send the first n items. + items=items[:num_items] + ) + return ( + 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s' + % (test.name, test.filename, lineno, lname, err) + ) + + def omitting_trailers(self) -> None: + get_collection( + hey_this_is_a_very_long_call, it_has_funny_attributes, really=True + )[OneLevelIndex] + get_collection( + hey_this_is_a_very_long_call, it_has_funny_attributes, really=True + )[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex] + d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][ + 22 + ] + assignment = ( + some.rather.elaborate.rule() and another.rule.ending_with.index[123] + ) + + def easy_asserts(self) -> None: + assert { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + } == expected, "Not what we expected" + + assert expected == { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + }, "Not what we expected" + + assert expected == { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + } + + def tricky_asserts(self) -> None: + assert { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + } == expected( + value, is_going_to_be="too long to fit in a single line", srsly=True + ), "Not what we expected" + + assert { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + } == expected, ( + "Not what we expected and the message is too long to fit in one line" + ) + + assert expected( + value, is_going_to_be="too long to fit in a single line", srsly=True + ) == { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + }, "Not what we expected" + + assert expected == { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + }, ( + "Not what we expected and the message is too long to fit in one line" + " because it's too long" + ) + + dis_c_instance_method = """\ + %3d 0 LOAD_FAST 1 (x) + 2 LOAD_CONST 1 (1) + 4 COMPARE_OP 2 (==) + 6 LOAD_FAST 0 (self) + 8 STORE_ATTR 0 (x) + 10 LOAD_CONST 0 (None) + 12 RETURN_VALUE + """ % ( + _C.__init__.__code__.co_firstlineno + 1, + ) + + assert ( + expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect + == { + key1: value1, + key2: value2, + key3: value3, + key4: value4, + key5: value5, + key6: value6, + key7: value7, + key8: value8, + key9: value9, + } + ) +``` + + diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_no_extra_empty_line_before_eof_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_no_extra_empty_line_before_eof_py.snap new file mode 100644 index 0000000000..69d1e86ad3 --- /dev/null +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_no_extra_empty_line_before_eof_py.snap @@ -0,0 +1,45 @@ +--- +source: crates/ruff_python_formatter/src/lib.rs +expression: snapshot +input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_no_extra_empty_line_before_eof.py +--- +## Input + +```py +# Make sure when the file ends with class's docstring, +# It doesn't add extra blank lines. +class ClassWithDocstring: + """A docstring.""" +``` + +## Black Differences + +```diff +--- Black ++++ Ruff +@@ -1,4 +1,3 @@ + # Make sure when the file ends with class's docstring, + # It doesn't add extra blank lines. +-class ClassWithDocstring: +- """A docstring.""" ++NOT_YET_IMPLEMENTED_StmtClassDef +``` + +## Ruff Output + +```py +# Make sure when the file ends with class's docstring, +# It doesn't add extra blank lines. +NOT_YET_IMPLEMENTED_StmtClassDef +``` + +## Black Output + +```py +# Make sure when the file ends with class's docstring, +# It doesn't add extra blank lines. +class ClassWithDocstring: + """A docstring.""" +``` + + diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_preview_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_preview_py.snap index b95e94cf32..3cb82ea680 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_preview_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_preview_py.snap @@ -63,81 +63,98 @@ def single_quote_docstring_over_line_limit2(): ```diff --- Black +++ Ruff -@@ -1,9 +1,11 @@ - def docstring_almost_at_line_limit(): +@@ -1,48 +1,28 @@ +-def docstring_almost_at_line_limit(): - """long docstring.................................................................""" -+ """long docstring................................................................. -+ """ ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def docstring_almost_at_line_limit_with_prefix(): +-def docstring_almost_at_line_limit_with_prefix(): - f"""long docstring................................................................""" -+ f"""long docstring................................................................ -+ """ ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def mulitline_docstring_almost_at_line_limit(): -@@ -45,4 +47,4 @@ +-def mulitline_docstring_almost_at_line_limit(): +- """long docstring................................................................. ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +- .................................................................................. +- """ + ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +-def mulitline_docstring_almost_at_line_limit_with_prefix(): +- f"""long docstring................................................................ + +- .................................................................................. +- """ ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def single_quote_docstring_over_line_limit2(): +-def docstring_at_line_limit(): +- """long docstring................................................................""" ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-def docstring_at_line_limit_with_prefix(): +- f"""long docstring...............................................................""" ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-def multiline_docstring_at_line_limit(): +- """first line----------------------------------------------------------------------- +- +- second line----------------------------------------------------------------------""" ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-def multiline_docstring_at_line_limit_with_prefix(): +- f"""first line---------------------------------------------------------------------- +- +- second line----------------------------------------------------------------------""" ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-def single_quote_docstring_over_line_limit(): - "We do not want to put the closing quote on a new line as that is invalid (see GH-3141)." -+ 'We do not want to put the closing quote on a new line as that is invalid (see GH-3141).' +- +- +-def single_quote_docstring_over_line_limit2(): +- "We do not want to put the closing quote on a new line as that is invalid (see GH-3141)." ++NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Ruff Output ```py -def docstring_almost_at_line_limit(): - """long docstring................................................................. - """ +NOT_YET_IMPLEMENTED_StmtFunctionDef -def docstring_almost_at_line_limit_with_prefix(): - f"""long docstring................................................................ - """ +NOT_YET_IMPLEMENTED_StmtFunctionDef -def mulitline_docstring_almost_at_line_limit(): - """long docstring................................................................. - - .................................................................................. - """ +NOT_YET_IMPLEMENTED_StmtFunctionDef -def mulitline_docstring_almost_at_line_limit_with_prefix(): - f"""long docstring................................................................ - - .................................................................................. - """ +NOT_YET_IMPLEMENTED_StmtFunctionDef -def docstring_at_line_limit(): - """long docstring................................................................""" +NOT_YET_IMPLEMENTED_StmtFunctionDef -def docstring_at_line_limit_with_prefix(): - f"""long docstring...............................................................""" +NOT_YET_IMPLEMENTED_StmtFunctionDef -def multiline_docstring_at_line_limit(): - """first line----------------------------------------------------------------------- - - second line----------------------------------------------------------------------""" +NOT_YET_IMPLEMENTED_StmtFunctionDef -def multiline_docstring_at_line_limit_with_prefix(): - f"""first line---------------------------------------------------------------------- - - second line----------------------------------------------------------------------""" +NOT_YET_IMPLEMENTED_StmtFunctionDef -def single_quote_docstring_over_line_limit(): - "We do not want to put the closing quote on a new line as that is invalid (see GH-3141)." +NOT_YET_IMPLEMENTED_StmtFunctionDef -def single_quote_docstring_over_line_limit2(): - 'We do not want to put the closing quote on a new line as that is invalid (see GH-3141).' +NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Black Output 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 58b5b5f29c..ef8190c5d1 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 @@ -234,86 +234,64 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self): ```diff --- Black +++ Ruff -@@ -1,83 +1,85 @@ - class MyClass: -+ """ Multiline -+ class docstring -+ """ -+ -+ def method(self): - """Multiline +@@ -1,219 +1,105 @@ +-class MyClass: +- """Multiline - class docstring -+ method docstring - """ -- +- """ ++NOT_YET_IMPLEMENTED_StmtClassDef + - def method(self): - """Multiline - method docstring - """ - pass -+ pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def foo(): +-def foo(): - """This is a docstring with - some lines of text here - """ - return -+ """This is a docstring with -+ some lines of text here -+ """ -+ return ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def bar(): +-def bar(): - """This is another docstring - with more lines of text - """ - return -+ '''This is another docstring -+ with more lines of text -+ ''' -+ return ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def baz(): +-def baz(): - '''"This" is a string with some - embedded "quotes"''' - return -+ '''"This" is a string with some -+ embedded "quotes"''' -+ return ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def troz(): +-def troz(): - """Indentation with tabs - is just as OK - """ - return -+ '''Indentation with tabs -+ is just as OK -+ ''' -+ return ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def zort(): +-def zort(): - """Another - multiline - docstring - """ - pass -+ """Another -+ multiline -+ docstring -+ """ -+ pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def poit(): +-def poit(): - """ - Lorem ipsum dolor sit amet. -+ """ -+ Lorem ipsum dolor sit amet. - Consectetur adipiscing elit: - - sed do eiusmod tempor incididunt ut labore @@ -323,133 +301,110 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self): - - aliquip ex ea commodo consequat - """ - pass -+ Consectetur adipiscing elit: -+ - sed do eiusmod tempor incididunt ut labore -+ - dolore magna aliqua -+ - enim ad minim veniam -+ - quis nostrud exercitation ullamco laboris nisi -+ - aliquip ex ea commodo consequat -+ """ -+ pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def under_indent(): +-def under_indent(): - """ - These lines are indented in a way that does not - make sense. - """ - pass -+ """ -+ These lines are indented in a way that does not -+make sense. -+ """ -+ pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def over_indent(): +-def over_indent(): - """ - This has a shallow indent - - But some lines are deeper - - And the closing quote is too deep -+ """ -+ This has a shallow indent -+ - But some lines are deeper -+ - And the closing quote is too deep - """ +- """ - pass -+ pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def single_line(): +-def single_line(): - """But with a newline after it!""" -+ """But with a newline after it! -+ -+ """ - pass +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef -@@ -88,25 +90,30 @@ +-def this(): +- r""" +- 'hey ho' +- """ ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def that(): +-def that(): - """ "hey yah" """ -+ """ "hey yah" """ ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def and_that(): +-def and_that(): - """ - "hey yah" """ -+ """ -+ "hey yah" """ ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def and_this(): +-def and_this(): - ''' - "hey yah"''' -+ ''' -+ "hey yah"''' ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def multiline_whitespace(): +-def multiline_whitespace(): - """ """ -+ ''' -+ -+ -+ -+ -+ ''' ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def oneline_whitespace(): +-def oneline_whitespace(): - """ """ -+ ''' ''' ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def empty(): -@@ -114,12 +121,11 @@ +-def empty(): +- """""" ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def single_quotes(): +-def single_quotes(): - "testing" -+ 'testing' - +- ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def believe_it_or_not_this_is_in_the_py_stdlib(): - ''' - "hey yah"''' -+def believe_it_or_not_this_is_in_the_py_stdlib(): ''' -+"hey yah"''' ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def ignored_docstring(): -@@ -128,32 +134,32 @@ +-def ignored_docstring(): +- """a => \ +-b""" ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def single_line_docstring_with_whitespace(): +-def single_line_docstring_with_whitespace(): - """This should be stripped""" -+ """ This should be stripped """ ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def docstring_with_inline_tabs_and_space_indentation(): - """hey +-def docstring_with_inline_tabs_and_space_indentation(): +- """hey - tab separated value +- tab separated value - tab at start of line and then a tab separated value - multiple tabs at the beginning and inline - mixed tabs and spaces at beginning. next line has mixed tabs and spaces only. - - line ends with some tabs -+ tab at start of line and then a tab separated value -+ multiple tabs at the beginning and inline -+ mixed tabs and spaces at beginning. next line has mixed tabs and spaces only. -+ -+ line ends with some tabs - """ +- """ +- ++NOT_YET_IMPLEMENTED_StmtFunctionDef - - def docstring_with_inline_tabs_and_tab_indentation(): +-def docstring_with_inline_tabs_and_tab_indentation(): - """hey -+ """hey - tab separated value - tab at start of line and then a tab separated value @@ -459,296 +414,191 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self): - line ends with some tabs - """ - pass -+ tab separated value -+ tab at start of line and then a tab separated value -+ multiple tabs at the beginning and inline -+ mixed tabs and spaces at beginning. next line has mixed tabs and spaces only. -+ -+ line ends with some tabs -+ """ -+ pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def backslash_space(): -@@ -161,14 +167,14 @@ +-def backslash_space(): +- """\ """ ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def multiline_backslash_1(): +-def multiline_backslash_1(): - """ -+ ''' - hey\there\ +- hey\there\ - \ """ -+ \ ''' - - - def multiline_backslash_2(): +- +- +-def multiline_backslash_2(): - """ - hey there \ """ -+ ''' -+ hey there \ ''' ++NOT_YET_IMPLEMENTED_StmtFunctionDef # Regression test for #3425 -@@ -178,8 +184,8 @@ +-def multiline_backslash_really_long_dont_crash(): +- """ +- hey there hello guten tag hi hoow are you ola zdravstvuyte ciao como estas ca va \ """ ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def multiline_backslash_3(): +-def multiline_backslash_3(): - """ - already escaped \\""" -+ ''' -+ already escaped \\ ''' ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def my_god_its_full_of_stars_1(): -@@ -188,7 +194,7 @@ +-def my_god_its_full_of_stars_1(): +- "I'm sorry Dave\u2001" ++NOT_YET_IMPLEMENTED_StmtFunctionDef + # the space below is actually a \u2001, removed in output - def my_god_its_full_of_stars_2(): +-def my_god_its_full_of_stars_2(): - "I'm sorry Dave" -+ "I'm sorry Dave " ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def docstring_almost_at_line_limit(): -@@ -213,7 +219,7 @@ - - - def stable_quote_normalization_with_immediate_inner_single_quote(self): -- """' -+ '''' - - +-def docstring_almost_at_line_limit(): +- """long docstring.................................................................""" +- +- +-def docstring_almost_at_line_limit2(): +- """long docstring................................................................. +- +- .................................................................................. - """ -+ ''' ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-def docstring_at_line_limit(): +- """long docstring................................................................""" ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-def multiline_docstring_at_line_limit(): +- """first line----------------------------------------------------------------------- ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +- second line----------------------------------------------------------------------""" + ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +-def stable_quote_normalization_with_immediate_inner_single_quote(self): +- """' + +- +- """ ++NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Ruff Output ```py -class MyClass: - """ Multiline - class docstring - """ - - def method(self): - """Multiline - method docstring - """ - pass +NOT_YET_IMPLEMENTED_StmtClassDef -def foo(): - """This is a docstring with - some lines of text here - """ - return +NOT_YET_IMPLEMENTED_StmtFunctionDef -def bar(): - '''This is another docstring - with more lines of text - ''' - return +NOT_YET_IMPLEMENTED_StmtFunctionDef -def baz(): - '''"This" is a string with some - embedded "quotes"''' - return +NOT_YET_IMPLEMENTED_StmtFunctionDef -def troz(): - '''Indentation with tabs - is just as OK - ''' - return +NOT_YET_IMPLEMENTED_StmtFunctionDef -def zort(): - """Another - multiline - docstring - """ - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def poit(): - """ - Lorem ipsum dolor sit amet. - - Consectetur adipiscing elit: - - sed do eiusmod tempor incididunt ut labore - - dolore magna aliqua - - enim ad minim veniam - - quis nostrud exercitation ullamco laboris nisi - - aliquip ex ea commodo consequat - """ - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def under_indent(): - """ - These lines are indented in a way that does not -make sense. - """ - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def over_indent(): - """ - This has a shallow indent - - But some lines are deeper - - And the closing quote is too deep - """ - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def single_line(): - """But with a newline after it! - - """ - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def this(): - r""" - 'hey ho' - """ +NOT_YET_IMPLEMENTED_StmtFunctionDef -def that(): - """ "hey yah" """ +NOT_YET_IMPLEMENTED_StmtFunctionDef -def and_that(): - """ - "hey yah" """ +NOT_YET_IMPLEMENTED_StmtFunctionDef -def and_this(): - ''' - "hey yah"''' +NOT_YET_IMPLEMENTED_StmtFunctionDef -def multiline_whitespace(): - ''' - - - - - ''' +NOT_YET_IMPLEMENTED_StmtFunctionDef -def oneline_whitespace(): - ''' ''' +NOT_YET_IMPLEMENTED_StmtFunctionDef -def empty(): - """""" +NOT_YET_IMPLEMENTED_StmtFunctionDef -def single_quotes(): - 'testing' +NOT_YET_IMPLEMENTED_StmtFunctionDef -def believe_it_or_not_this_is_in_the_py_stdlib(): ''' -"hey yah"''' +NOT_YET_IMPLEMENTED_StmtFunctionDef -def ignored_docstring(): - """a => \ -b""" +NOT_YET_IMPLEMENTED_StmtFunctionDef -def single_line_docstring_with_whitespace(): - """ This should be stripped """ +NOT_YET_IMPLEMENTED_StmtFunctionDef -def docstring_with_inline_tabs_and_space_indentation(): - """hey - - tab separated value - tab at start of line and then a tab separated value - multiple tabs at the beginning and inline - mixed tabs and spaces at beginning. next line has mixed tabs and spaces only. - - line ends with some tabs - """ +NOT_YET_IMPLEMENTED_StmtFunctionDef -def docstring_with_inline_tabs_and_tab_indentation(): - """hey - - tab separated value - tab at start of line and then a tab separated value - multiple tabs at the beginning and inline - mixed tabs and spaces at beginning. next line has mixed tabs and spaces only. - - line ends with some tabs - """ - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def backslash_space(): - """\ """ +NOT_YET_IMPLEMENTED_StmtFunctionDef -def multiline_backslash_1(): - ''' - hey\there\ - \ ''' +NOT_YET_IMPLEMENTED_StmtFunctionDef -def multiline_backslash_2(): - ''' - hey there \ ''' +NOT_YET_IMPLEMENTED_StmtFunctionDef # Regression test for #3425 -def multiline_backslash_really_long_dont_crash(): - """ - hey there hello guten tag hi hoow are you ola zdravstvuyte ciao como estas ca va \ """ +NOT_YET_IMPLEMENTED_StmtFunctionDef -def multiline_backslash_3(): - ''' - already escaped \\ ''' +NOT_YET_IMPLEMENTED_StmtFunctionDef -def my_god_its_full_of_stars_1(): - "I'm sorry Dave\u2001" +NOT_YET_IMPLEMENTED_StmtFunctionDef # the space below is actually a \u2001, removed in output -def my_god_its_full_of_stars_2(): - "I'm sorry Dave " +NOT_YET_IMPLEMENTED_StmtFunctionDef -def docstring_almost_at_line_limit(): - """long docstring.................................................................""" +NOT_YET_IMPLEMENTED_StmtFunctionDef -def docstring_almost_at_line_limit2(): - """long docstring................................................................. - - .................................................................................. - """ +NOT_YET_IMPLEMENTED_StmtFunctionDef -def docstring_at_line_limit(): - """long docstring................................................................""" +NOT_YET_IMPLEMENTED_StmtFunctionDef -def multiline_docstring_at_line_limit(): - """first line----------------------------------------------------------------------- - - second line----------------------------------------------------------------------""" +NOT_YET_IMPLEMENTED_StmtFunctionDef -def stable_quote_normalization_with_immediate_inner_single_quote(self): - '''' - - - ''' +NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__empty_lines_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__empty_lines_py.snap index 9782dc0171..7502ae2280 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__empty_lines_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__empty_lines_py.snap @@ -105,162 +105,116 @@ def g(): ```diff --- Black +++ Ruff -@@ -3,9 +3,9 @@ +@@ -1,89 +1,12 @@ +-"""Docstring.""" ++NOT_YET_IMPLEMENTED_ExprConstant + # leading comment - def f(): +-def f(): - NO = "" - SPACE = " " - DOUBLESPACE = " " -+ NO = '' -+ SPACE = ' ' -+ DOUBLESPACE = ' ' +- +- t = leaf.type +- p = leaf.parent # trailing comment +- v = leaf.value +- +- if t in ALWAYS_NO_SPACE: +- pass +- if t == token.COMMENT: # another trailing comment +- return DOUBLESPACE +- +- assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}" +- +- prev = leaf.prev_sibling +- if not prev: +- prevp = preceding_leaf(p) +- if not prevp or prevp.type in OPENING_BRACKETS: +- return NO +- +- if prevp.type == token.EQUAL: +- if prevp.parent and prevp.parent.type in { +- syms.typedargslist, +- syms.varargslist, +- syms.parameters, +- syms.arglist, +- syms.argument, +- }: +- return NO +- +- elif prevp.type == token.DOUBLESTAR: +- if prevp.parent and prevp.parent.type in { +- syms.typedargslist, +- syms.varargslist, +- syms.parameters, +- syms.arglist, +- syms.dictsetmaker, +- }: +- return NO ++NOT_YET_IMPLEMENTED_StmtFunctionDef - t = leaf.type - p = leaf.parent # trailing comment -@@ -16,14 +16,19 @@ - if t == token.COMMENT: # another trailing comment - return DOUBLESPACE -+ - assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}" - -+ - prev = leaf.prev_sibling - if not prev: - prevp = preceding_leaf(p) - if not prevp or prevp.type in OPENING_BRACKETS: -+ -+ - return NO - -+ - if prevp.type == token.EQUAL: - if prevp.parent and prevp.parent.type in { - syms.typedargslist, -@@ -48,12 +53,11 @@ ############################################################################### # SECTION BECAUSE SECTIONS ############################################################################### - - def g(): +-def g(): - NO = "" - SPACE = " " - DOUBLESPACE = " " -+ NO = '' -+ SPACE = ' ' -+ DOUBLESPACE = ' ' - - t = leaf.type - p = leaf.parent -@@ -67,7 +71,7 @@ - return DOUBLESPACE - - # Another comment because more comments +- +- t = leaf.type +- p = leaf.parent +- v = leaf.value +- +- # Comment because comments +- +- if t in ALWAYS_NO_SPACE: +- pass +- if t == token.COMMENT: +- return DOUBLESPACE +- +- # Another comment because more comments - assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}" -+ assert p is not None, f'INTERNAL ERROR: hand-made leaf without parent: {leaf!r}' - - prev = leaf.prev_sibling - if not prev: +- +- prev = leaf.prev_sibling +- if not prev: +- prevp = preceding_leaf(p) +- +- if not prevp or prevp.type in OPENING_BRACKETS: +- # Start of the line or a bracketed expression. +- # More than one line for the comment. +- return NO +- +- if prevp.type == token.EQUAL: +- if prevp.parent and prevp.parent.type in { +- syms.typedargslist, +- syms.varargslist, +- syms.parameters, +- syms.arglist, +- syms.argument, +- }: +- return NO ++NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Ruff Output ```py -"""Docstring.""" +NOT_YET_IMPLEMENTED_ExprConstant # leading comment -def f(): - NO = '' - SPACE = ' ' - DOUBLESPACE = ' ' - - t = leaf.type - p = leaf.parent # trailing comment - v = leaf.value - - if t in ALWAYS_NO_SPACE: - pass - if t == token.COMMENT: # another trailing comment - return DOUBLESPACE - - - assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}" - - - prev = leaf.prev_sibling - if not prev: - prevp = preceding_leaf(p) - if not prevp or prevp.type in OPENING_BRACKETS: - - - return NO - - - if prevp.type == token.EQUAL: - if prevp.parent and prevp.parent.type in { - syms.typedargslist, - syms.varargslist, - syms.parameters, - syms.arglist, - syms.argument, - }: - return NO - - elif prevp.type == token.DOUBLESTAR: - if prevp.parent and prevp.parent.type in { - syms.typedargslist, - syms.varargslist, - syms.parameters, - syms.arglist, - syms.dictsetmaker, - }: - return NO +NOT_YET_IMPLEMENTED_StmtFunctionDef ############################################################################### # SECTION BECAUSE SECTIONS ############################################################################### -def g(): - NO = '' - SPACE = ' ' - DOUBLESPACE = ' ' - - t = leaf.type - p = leaf.parent - v = leaf.value - - # Comment because comments - - if t in ALWAYS_NO_SPACE: - pass - if t == token.COMMENT: - return DOUBLESPACE - - # Another comment because more comments - assert p is not None, f'INTERNAL ERROR: hand-made leaf without parent: {leaf!r}' - - prev = leaf.prev_sibling - if not prev: - prevp = preceding_leaf(p) - - if not prevp or prevp.type in OPENING_BRACKETS: - # Start of the line or a bracketed expression. - # More than one line for the comment. - return NO - - if prevp.type == token.EQUAL: - if prevp.parent and prevp.parent.type in { - syms.typedargslist, - syms.varargslist, - syms.parameters, - syms.arglist, - syms.argument, - }: - return NO +NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__expression_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__expression_py.snap index 41c8b644da..0c9b90cdfa 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__expression_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__expression_py.snap @@ -267,116 +267,209 @@ last_call() ```diff --- Black +++ Ruff -@@ -1,5 +1,6 @@ +@@ -1,352 +1,253 @@ -"some_string" -b"\\xa3" -+... -+'some_string' -+b'\\xa3' ++NOT_YET_IMPLEMENTED_ExprConstant ++NOT_YET_IMPLEMENTED_ExprConstant ++NOT_YET_IMPLEMENTED_ExprConstant Name - None - True -@@ -30,56 +31,39 @@ - -1 - ~int and not v1 ^ 123 + v2 | True - (~int) and (not ((v1 ^ (123 + v2)) | True)) +-None +-True +-False +-1 +-1.0 +-1j +-True or False +-True or False or None +-True and False +-True and False and None +-(Name1 and Name2) or Name3 +-Name1 and Name2 or Name3 +-Name1 or (Name2 and Name3) +-Name1 or Name2 and Name3 +-(Name1 and Name2) or (Name3 and Name4) +-Name1 and Name2 or Name3 and Name4 +-Name1 or (Name2 and Name3) or Name4 +-Name1 or Name2 and Name3 or Name4 +-v1 << 2 +-1 >> v2 +-1 % finished +-1 + v2 - v3 * 4 ^ 5**v6 / 7 // 8 +-((1 + v2) - (v3 * 4)) ^ (((5**v6) / 7) // 8) +-not great +-~great +-+value +--1 +-~int and not v1 ^ 123 + v2 | True +-(~int) and (not ((v1 ^ (123 + v2)) | True)) -+(really ** -(confusing ** ~(operator**-precedence))) -flags & ~select.EPOLLIN and waiters.write_task is not None -++really ** -confusing ** ~operator ** -precedence -+flags & ~ select.EPOLLIN and waiters.write_task is not None - lambda arg: None - lambda a=True: a - lambda a, b, c=True: a +-lambda arg: None +-lambda a=True: a +-lambda a, b, c=True: a -lambda a, b, c=True, *, d=(1 << v2), e="str": a -lambda a, b, c=True, *vararg, d=(v1 << 2), e="str", **kwargs: a + b -+lambda a, b, c=True, *, d=(1 << v2), e='str': a -+lambda a, b, c=True, *vararg, d=(v1 << 2), e='str', **kwargs: a + b - manylambdas = lambda x=lambda y=lambda z=1: z: y(): x() +-manylambdas = lambda x=lambda y=lambda z=1: z: y(): x() -foo = lambda port_id, ignore_missing: { - "port1": port1_resource, - "port2": port2_resource, -}[port_id] -+foo = (lambda port_id, ignore_missing: {"port1": port1_resource, "port2": port2_resource}[port_id]) - 1 if True else 2 - str or None if True else str or bytes or None - (str or None) if True else (str or bytes or None) - str or None if (1 if True else 2) else str or bytes or None - (str or None) if (1 if True else 2) else (str or bytes or None) +-1 if True else 2 +-str or None if True else str or bytes or None +-(str or None) if True else (str or bytes or None) +-str or None if (1 if True else 2) else str or bytes or None +-(str or None) if (1 if True else 2) else (str or bytes or None) ++NOT_YET_IMPLEMENTED_ExprConstant ++NOT_YET_IMPLEMENTED_ExprConstant ++NOT_YET_IMPLEMENTED_ExprConstant ++NOT_YET_IMPLEMENTED_ExprConstant ++NOT_YET_IMPLEMENTED_ExprConstant ++NOT_YET_IMPLEMENTED_ExprConstant ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++v1 << NOT_YET_IMPLEMENTED_ExprConstant ++NOT_YET_IMPLEMENTED_ExprConstant >> v2 ++NOT_YET_IMPLEMENTED_ExprConstant % finished ( - (super_long_variable_name or None) - if (1 if super_long_test_name else 2) - else (str or bytes or None) -+ (super_long_variable_name or None) if (1 if super_long_test_name else 2) else (str or bytes or None) ++ NOT_YET_IMPLEMENTED_ExprConstant ++ + v2 ++ - v3 * NOT_YET_IMPLEMENTED_ExprConstant ++ ^ NOT_YET_IMPLEMENTED_ExprConstant ++ **v6 ++ / NOT_YET_IMPLEMENTED_ExprConstant ++ // NOT_YET_IMPLEMENTED_ExprConstant ) -{"2.7": dead, "3.7": (long_live or die_hard)} -{"2.7": dead, "3.7": (long_live or die_hard), **{"3.6": verygood}} -+{'2.7': dead, '3.7': (long_live or die_hard)} -+{'2.7': dead, '3.7': (long_live or die_hard), **{'3.6': verygood}} - {**a, **b, **c} +-{**a, **b, **c} -{"2.7", "3.6", "3.7", "3.8", "3.9", ("4.0" if gilectomy else "3.10")} -({"a": "b"}, (True or False), (+value), "string", b"bytes") or None -+{'2.7', '3.6', '3.7', '3.8', '3.9', ('4.0' if gilectomy else '3.10')} -+({'a': 'b'}, (True or False), (+value), 'string', b'bytes') or None - () - (1,) - (1, 2) - (1, 2, 3) +-() +-(1,) +-(1, 2) +-(1, 2, 3) ++( ++ ((NOT_YET_IMPLEMENTED_ExprConstant + v2) - (v3 * NOT_YET_IMPLEMENTED_ExprConstant)) ++ ^ ( ++ ((NOT_YET_IMPLEMENTED_ExprConstant**v6) / NOT_YET_IMPLEMENTED_ExprConstant) ++ // NOT_YET_IMPLEMENTED_ExprConstant ++ ) ++) ++NOT_YET_IMPLEMENTED_ExprUnaryOp ++NOT_YET_IMPLEMENTED_ExprUnaryOp ++NOT_YET_IMPLEMENTED_ExprUnaryOp ++NOT_YET_IMPLEMENTED_ExprUnaryOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprUnaryOp ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprLambda ++NOT_YET_IMPLEMENTED_ExprLambda ++NOT_YET_IMPLEMENTED_ExprLambda ++NOT_YET_IMPLEMENTED_ExprLambda ++NOT_YET_IMPLEMENTED_ExprLambda ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_ExprIfExp ++NOT_YET_IMPLEMENTED_ExprIfExp ++NOT_YET_IMPLEMENTED_ExprIfExp ++NOT_YET_IMPLEMENTED_ExprIfExp ++NOT_YET_IMPLEMENTED_ExprIfExp ++(NOT_YET_IMPLEMENTED_ExprIfExp) ++NOT_YET_IMPLEMENTED_ExprDict ++NOT_YET_IMPLEMENTED_ExprDict ++NOT_YET_IMPLEMENTED_ExprDict ++NOT_YET_IMPLEMENTED_ExprSet ++NOT_YET_IMPLEMENTED_ExprBoolOp ++NOT_YET_IMPLEMENTED_ExprTuple ++NOT_YET_IMPLEMENTED_ExprTuple ++NOT_YET_IMPLEMENTED_ExprTuple ++NOT_YET_IMPLEMENTED_ExprTuple [] - [1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)] --[ +-[1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)] + [ - 1, - 2, - 3, --] -+[1, 2, 3] - [*a] - [*range(10)] --[ ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ (NOT_YET_IMPLEMENTED_ExprBoolOp), ++ (NOT_YET_IMPLEMENTED_ExprBoolOp), ++ (NOT_YET_IMPLEMENTED_ExprBoolOp), ++] ++[ ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, + ] +-[*a] +-[*range(10)] ++[NOT_YET_IMPLEMENTED_ExprStarred] ++[NOT_YET_IMPLEMENTED_ExprStarred] + [ - *a, - 4, - 5, --] --[ ++ NOT_YET_IMPLEMENTED_ExprStarred, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, + ] + [ - 4, - *a, - 5, --] -+[*a, 4, 5] -+[4, *a, 5] ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprStarred, ++ NOT_YET_IMPLEMENTED_ExprConstant, + ] [ this_is_a_very_long_variable_which_will_force_a_delimiter_split, element, -@@ -87,54 +71,44 @@ - *more, + another, +- *more, ++ NOT_YET_IMPLEMENTED_ExprStarred, ] - {i for i in (1, 2, 3)} +-{i for i in (1, 2, 3)} -{(i**2) for i in (1, 2, 3)} -{(i**2) for i, _ in ((1, "a"), (2, "b"), (3, "c"))} -{((i**2) + j) for i in (1, 2, 3) for j in (1, 2, 3)} -+{(i ** 2) for i in (1, 2, 3)} -+{(i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))} -+{((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)} - [i for i in (1, 2, 3)] +-[i for i in (1, 2, 3)] -[(i**2) for i in (1, 2, 3)] -[(i**2) for i, _ in ((1, "a"), (2, "b"), (3, "c"))] -[((i**2) + j) for i in (1, 2, 3) for j in (1, 2, 3)] -+[(i ** 2) for i in (1, 2, 3)] -+[(i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))] -+[((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)] - {i: 0 for i in (1, 2, 3)} +-{i: 0 for i in (1, 2, 3)} -{i: j for i, j in ((1, "a"), (2, "b"), (3, "c"))} -+{i: j for i, j in ((1, 'a'), (2, 'b'), (3, 'c'))} - {a: b * 2 for a, b in dictionary.items()} - {a: b * -2 for a, b in dictionary.items()} +-{a: b * 2 for a, b in dictionary.items()} +-{a: b * -2 for a, b in dictionary.items()} -{ - k: v - for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension -} -+{k: v for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension} - Python3 > Python2 > COBOL - Life is Life - call() - call(arg) +-Python3 > Python2 > COBOL +-Life is Life +-call() +-call(arg) -call(kwarg="hey") -call(arg, kwarg="hey") -call(arg, another, kwarg="hey", **kwargs) @@ -387,72 +480,156 @@ last_call() - kwarg="hey", - **kwargs, -) # note: no trailing comma pre-3.6 -+call(kwarg='hey') -+call(arg, kwarg='hey') -+call(arg, another, kwarg='hey', **kwargs) -+call(this_is_a_very_long_variable_which_will_force_a_delimiter_split, arg, another, kwarg='hey', **kwargs) # note: no trailing comma pre-3.6 - call(*gidgets[:2]) - call(a, *gidgets[:2]) - call(**self.screen_kwargs) - call(b, **self.screen_kwargs) - lukasz.langa.pl - call.me(maybe) +-call(*gidgets[:2]) +-call(a, *gidgets[:2]) +-call(**self.screen_kwargs) +-call(b, **self.screen_kwargs) +-lukasz.langa.pl +-call.me(maybe) -(1).real -(1.0).real -+1 .real -+1.0 .real - ....__class__ - list[str] - dict[str, int] - tuple[str, ...] +-....__class__ +-list[str] +-dict[str, int] +-tuple[str, ...] -tuple[str, int, float, dict[str, int]] -tuple[ - str, - int, - float, - dict[str, int], -+( -+ tuple[ -+ str, int, float, dict[str, int] ++NOT_YET_IMPLEMENTED_ExprSetComp ++NOT_YET_IMPLEMENTED_ExprSetComp ++NOT_YET_IMPLEMENTED_ExprSetComp ++NOT_YET_IMPLEMENTED_ExprSetComp ++NOT_YET_IMPLEMENTED_ExprListComp ++NOT_YET_IMPLEMENTED_ExprListComp ++NOT_YET_IMPLEMENTED_ExprListComp ++NOT_YET_IMPLEMENTED_ExprListComp ++NOT_YET_IMPLEMENTED_ExprDictComp ++NOT_YET_IMPLEMENTED_ExprDictComp ++NOT_YET_IMPLEMENTED_ExprDictComp ++NOT_YET_IMPLEMENTED_ExprDictComp ++NOT_YET_IMPLEMENTED_ExprDictComp ++NOT_YET_IMPLEMENTED_ExprCompare ++NOT_YET_IMPLEMENTED_ExprCompare ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_ExprCall # note: no trailing comma pre-3.6 ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_ExprAttribute ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_ExprAttribute ++NOT_YET_IMPLEMENTED_ExprAttribute ++NOT_YET_IMPLEMENTED_ExprAttribute ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_StmtAnnAssign ++NOT_YET_IMPLEMENTED_StmtAnnAssign ++NOT_YET_IMPLEMENTED_StmtAnnAssign ++NOT_YET_IMPLEMENTED_StmtAnnAssign # type: ignore ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprIfExp ++NOT_YET_IMPLEMENTED_ExprDict ++NOT_YET_IMPLEMENTED_ExprSet ++[ ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprConstant, ++ NOT_YET_IMPLEMENTED_ExprBoolOp, ++ NOT_YET_IMPLEMENTED_ExprBoolOp, ++ NOT_YET_IMPLEMENTED_ExprBoolOp, ] -+) -+tuple[str, int, float, dict[str, int],] - very_long_variable_name_filters: t.List[ - t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]], - ] -@@ -144,9 +118,9 @@ - xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore - sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) - ) +-very_long_variable_name_filters: t.List[ +- t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]], +-] +-xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore +- sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) +-) +-xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore +- sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) +-) -xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( - sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) -) # type: ignore -+xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[ -+ ..., List[SomeClass] -+] = classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) # type: ignore - slice[0] - slice[0:1] - slice[0:1:2] -@@ -174,57 +148,29 @@ - numpy[:, ::-1] - numpy[np.newaxis, :] - (str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None) +-slice[0] +-slice[0:1] +-slice[0:1:2] +-slice[:] +-slice[:-1] +-slice[1:] +-slice[::-1] +-slice[d :: d + 1] +-slice[:c, c - 1] +-numpy[:, 0:1] +-numpy[:, :-1] +-numpy[0, :] +-numpy[:, i] +-numpy[0, :2] +-numpy[:N, 0] +-numpy[:2, :4] +-numpy[2:4, 1:5] +-numpy[4:, 2:] +-numpy[:, (0, 1, 2, 5)] +-numpy[0, [0]] +-numpy[:, [i]] +-numpy[1 : c + 1, c] +-numpy[-(c + 1) :, d] +-numpy[:, l[-2]] +-numpy[:, ::-1] +-numpy[np.newaxis, :] +-(str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None) -{"2.7": dead, "3.7": long_live or die_hard} -{"2.7", "3.6", "3.7", "3.8", "3.9", "4.0" if gilectomy else "3.10"} -+{'2.7': dead, '3.7': long_live or die_hard} -+{'2.7', '3.6', '3.7', '3.8', '3.9', '4.0' if gilectomy else '3.10'} - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C] +-[1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C] (SomeName) SomeName - (Good, Bad, Ugly) - (i for i in (1, 2, 3)) +-(Good, Bad, Ugly) +-(i for i in (1, 2, 3)) -((i**2) for i in (1, 2, 3)) -((i**2) for i, _ in ((1, "a"), (2, "b"), (3, "c"))) -(((i**2) + j) for i in (1, 2, 3) for j in (1, 2, 3)) -+((i ** 2) for i in (1, 2, 3)) -+((i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))) -+(((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)) - (*starred,) +-(*starred,) -{ - "id": "1", - "type": "type", @@ -462,15 +639,13 @@ last_call() - "import_session_id": 1, - **kwargs, -} -+{"id": "1","type": "type","started_at": now(),"ended_at": now() + timedelta(days=10),"priority": 1,"import_session_id": 1,**kwargs} - a = (1,) +-a = (1,) -b = (1,) -+b = 1, - c = 1 - d = (1,) + a + (2,) - e = (1,).count(1) - f = 1, *range(10) - g = 1, *"ten" +-c = 1 +-d = (1,) + a + (2,) +-e = (1,).count(1) +-f = 1, *range(10) +-g = 1, *"ten" -what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set( - vars_to_remove -) @@ -495,32 +670,52 @@ last_call() - ) - .all() -) -+what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(vars_to_remove) -+what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(vars_to_remove) -+result = session.query(models.Customer.id).filter(models.Customer.account_id == account_id, models.Customer.email == email_address).order_by(models.Customer.id.asc()).all() -+result = session.query(models.Customer.id).filter(models.Customer.account_id == account_id, models.Customer.email == email_address).order_by(models.Customer.id.asc(),).all() - Ø = set() - authors.łukasz.say_thanks() - mapping = { -@@ -237,114 +183,80 @@ +-Ø = set() +-authors.łukasz.say_thanks() +-mapping = { +- A: 0.25 * (10.0 / 12), +- B: 0.1 * (10.0 / 12), +- C: 0.1 * (10.0 / 12), +- D: 0.1 * (10.0 / 12), +-} ++NOT_YET_IMPLEMENTED_ExprTuple ++NOT_YET_IMPLEMENTED_ExprGeneratorExp ++NOT_YET_IMPLEMENTED_ExprGeneratorExp ++NOT_YET_IMPLEMENTED_ExprGeneratorExp ++NOT_YET_IMPLEMENTED_ExprGeneratorExp ++NOT_YET_IMPLEMENTED_ExprTuple ++NOT_YET_IMPLEMENTED_ExprDict ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_StmtAssign - def gen(): - yield from outside_of_generator + +-def gen(): +- yield from outside_of_generator - a = yield - b = yield - c = yield -+ a = (yield) -+ b = ((yield)) -+ c = (((yield))) ++NOT_YET_IMPLEMENTED_StmtFunctionDef - async def f(): - await some.complicated[0].call(with_args=(True or (1 is not 1))) +-async def f(): +- await some.complicated[0].call(with_args=(True or (1 is not 1))) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -print(*[] or [1]) -+print(* [] or [1]) - print(**{1: 3} if False else {x: x for x in range(3)}) +-print(**{1: 3} if False else {x: x for x in range(3)}) -print(*lambda x: x) -assert not Test, "Short message" -assert this is ComplexTest and not requirements.fit_in_a_single_line( @@ -537,17 +732,8 @@ last_call() - ... -for j in 1 + (2 + 3): - ... -+print(* lambda x: x) -+assert(not Test),("Short message") -+assert this is ComplexTest and not requirements.fit_in_a_single_line(force=False), "Short message" -+assert(((parens is TooMany))) -+for x, in (1,), (2,), (3,): ... -+for y in (): ... -+for z in (i for i in (1, 2, 3)): ... -+for i in (call()): ... -+for j in (1 + (2 + 3)): ... - while this and that: - ... +-while this and that: +- ... -for ( - addr_family, - addr_type, @@ -555,8 +741,7 @@ last_call() - addr_canonname, - addr_sockaddr, -) in socket.getaddrinfo("google.com", "http"): -+for addr_family, addr_type, addr_proto, addr_canonname, addr_sockaddr in socket.getaddrinfo('google.com', 'http'): - pass +- pass -a = ( - aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp - in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz @@ -573,69 +758,54 @@ last_call() - aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp - is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz -) -+a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz -+a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp not in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz -+a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp is qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz -+a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz - if ( +-if ( - threading.current_thread() != threading.main_thread() - and threading.current_thread() != threading.main_thread() - or signal.getsignal(signal.SIGINT) != signal.default_int_handler -+ threading.current_thread() != threading.main_thread() and -+ threading.current_thread() != threading.main_thread() or -+ signal.getsignal(signal.SIGINT) != signal.default_int_handler - ): - return True - if ( -+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +-): +- return True +-if ( +- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - ): - return True - if ( -+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +-): +- return True +-if ( +- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - ): - return True - if ( -+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +-): +- return True +-if ( +- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - ): - return True - if ( -+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +-): +- return True +-if ( +- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - ): - return True - if ( -+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +-): +- return True +-if ( +- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - ): - return True - if ( -+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa / - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +-): +- return True +-if ( +- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - / aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - ): - return True - if ( +-): +- return True +-if ( - ~aaaa.a + aaaa.b - aaaa.c * aaaa.d / aaaa.e - | aaaa.f & aaaa.g % aaaa.h ^ aaaa.i << aaaa.k >> aaaa.l**aaaa.m // aaaa.n -+ ~ aaaa.a + aaaa.b - aaaa.c * aaaa.d / aaaa.e | aaaa.f & aaaa.g % aaaa.h ^ aaaa.i << aaaa.k >> aaaa.l ** aaaa.m // aaaa.n - ): - return True - if ( +-): +- return True +-if ( - ~aaaaaaaa.a + aaaaaaaa.b - aaaaaaaa.c @ aaaaaaaa.d / aaaaaaaa.e - | aaaaaaaa.f & aaaaaaaa.g % aaaaaaaa.h - ^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l**aaaaaaaa.m // aaaaaaaa.n -+ ~ aaaaaaaa.a + aaaaaaaa.b - aaaaaaaa.c @ aaaaaaaa.d / aaaaaaaa.e | aaaaaaaa.f & aaaaaaaa.g % aaaaaaaa.h ^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l ** aaaaaaaa.m // aaaaaaaa.n - ): - return True - if ( +-): +- return True +-if ( - ~aaaaaaaaaaaaaaaa.a - + aaaaaaaaaaaaaaaa.b - - aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e @@ -643,276 +813,306 @@ last_call() - ^ aaaaaaaaaaaaaaaa.i - << aaaaaaaaaaaaaaaa.k - >> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n -+ ~ aaaaaaaaaaaaaaaa.a + aaaaaaaaaaaaaaaa.b - aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e | aaaaaaaaaaaaaaaa.f & aaaaaaaaaaaaaaaa.g % aaaaaaaaaaaaaaaa.h ^ aaaaaaaaaaaaaaaa.i << aaaaaaaaaaaaaaaa.k >> aaaaaaaaaaaaaaaa.l ** aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n - ): - return True +-): +- return True ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_ExprCall ++NOT_YET_IMPLEMENTED_StmtAssert ++NOT_YET_IMPLEMENTED_StmtAssert ++NOT_YET_IMPLEMENTED_StmtAssert ++NOT_YET_IMPLEMENTED_StmtFor ++NOT_YET_IMPLEMENTED_StmtFor ++NOT_YET_IMPLEMENTED_StmtFor ++NOT_YET_IMPLEMENTED_StmtFor ++NOT_YET_IMPLEMENTED_StmtFor ++while NOT_YET_IMPLEMENTED_ExprBoolOp: ++ NOT_YET_IMPLEMENTED_ExprConstant ++NOT_YET_IMPLEMENTED_StmtFor ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtIf ++NOT_YET_IMPLEMENTED_StmtIf ++NOT_YET_IMPLEMENTED_StmtIf ++NOT_YET_IMPLEMENTED_StmtIf ++NOT_YET_IMPLEMENTED_StmtIf ++NOT_YET_IMPLEMENTED_StmtIf ++NOT_YET_IMPLEMENTED_StmtIf ++NOT_YET_IMPLEMENTED_StmtIf ++NOT_YET_IMPLEMENTED_StmtIf ++NOT_YET_IMPLEMENTED_StmtIf ( + aaaaaaaaaaaaaaaa + + aaaaaaaaaaaaaaaa +@@ -363,8 +264,9 @@ + bbbb >> bbbb * bbbb + ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +- ^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ++ ^ NOT_YET_IMPLEMENTED_ExprAttribute ++ & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + ^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + ) +-last_call() ++NOT_YET_IMPLEMENTED_ExprCall + # standalone comment at ENDMARKER ``` ## Ruff Output ```py -... -'some_string' -b'\\xa3' +NOT_YET_IMPLEMENTED_ExprConstant +NOT_YET_IMPLEMENTED_ExprConstant +NOT_YET_IMPLEMENTED_ExprConstant Name -None -True -False -1 -1.0 -1j -True or False -True or False or None -True and False -True and False and None -(Name1 and Name2) or Name3 -Name1 and Name2 or Name3 -Name1 or (Name2 and Name3) -Name1 or Name2 and Name3 -(Name1 and Name2) or (Name3 and Name4) -Name1 and Name2 or Name3 and Name4 -Name1 or (Name2 and Name3) or Name4 -Name1 or Name2 and Name3 or Name4 -v1 << 2 -1 >> v2 -1 % finished -1 + v2 - v3 * 4 ^ 5**v6 / 7 // 8 -((1 + v2) - (v3 * 4)) ^ (((5**v6) / 7) // 8) -not great -~great -+value --1 -~int and not v1 ^ 123 + v2 | True -(~int) and (not ((v1 ^ (123 + v2)) | True)) -+really ** -confusing ** ~operator ** -precedence -flags & ~ select.EPOLLIN and waiters.write_task is not None -lambda arg: None -lambda a=True: a -lambda a, b, c=True: a -lambda a, b, c=True, *, d=(1 << v2), e='str': a -lambda a, b, c=True, *vararg, d=(v1 << 2), e='str', **kwargs: a + b -manylambdas = lambda x=lambda y=lambda z=1: z: y(): x() -foo = (lambda port_id, ignore_missing: {"port1": port1_resource, "port2": port2_resource}[port_id]) -1 if True else 2 -str or None if True else str or bytes or None -(str or None) if True else (str or bytes or None) -str or None if (1 if True else 2) else str or bytes or None -(str or None) if (1 if True else 2) else (str or bytes or None) +NOT_YET_IMPLEMENTED_ExprConstant +NOT_YET_IMPLEMENTED_ExprConstant +NOT_YET_IMPLEMENTED_ExprConstant +NOT_YET_IMPLEMENTED_ExprConstant +NOT_YET_IMPLEMENTED_ExprConstant +NOT_YET_IMPLEMENTED_ExprConstant +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprBoolOp +v1 << NOT_YET_IMPLEMENTED_ExprConstant +NOT_YET_IMPLEMENTED_ExprConstant >> v2 +NOT_YET_IMPLEMENTED_ExprConstant % finished ( - (super_long_variable_name or None) if (1 if super_long_test_name else 2) else (str or bytes or None) + NOT_YET_IMPLEMENTED_ExprConstant + + v2 + - v3 * NOT_YET_IMPLEMENTED_ExprConstant + ^ NOT_YET_IMPLEMENTED_ExprConstant + **v6 + / NOT_YET_IMPLEMENTED_ExprConstant + // NOT_YET_IMPLEMENTED_ExprConstant ) -{'2.7': dead, '3.7': (long_live or die_hard)} -{'2.7': dead, '3.7': (long_live or die_hard), **{'3.6': verygood}} -{**a, **b, **c} -{'2.7', '3.6', '3.7', '3.8', '3.9', ('4.0' if gilectomy else '3.10')} -({'a': 'b'}, (True or False), (+value), 'string', b'bytes') or None -() -(1,) -(1, 2) -(1, 2, 3) +( + ((NOT_YET_IMPLEMENTED_ExprConstant + v2) - (v3 * NOT_YET_IMPLEMENTED_ExprConstant)) + ^ ( + ((NOT_YET_IMPLEMENTED_ExprConstant**v6) / NOT_YET_IMPLEMENTED_ExprConstant) + // NOT_YET_IMPLEMENTED_ExprConstant + ) +) +NOT_YET_IMPLEMENTED_ExprUnaryOp +NOT_YET_IMPLEMENTED_ExprUnaryOp +NOT_YET_IMPLEMENTED_ExprUnaryOp +NOT_YET_IMPLEMENTED_ExprUnaryOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprUnaryOp +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprLambda +NOT_YET_IMPLEMENTED_ExprLambda +NOT_YET_IMPLEMENTED_ExprLambda +NOT_YET_IMPLEMENTED_ExprLambda +NOT_YET_IMPLEMENTED_ExprLambda +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_ExprIfExp +NOT_YET_IMPLEMENTED_ExprIfExp +NOT_YET_IMPLEMENTED_ExprIfExp +NOT_YET_IMPLEMENTED_ExprIfExp +NOT_YET_IMPLEMENTED_ExprIfExp +(NOT_YET_IMPLEMENTED_ExprIfExp) +NOT_YET_IMPLEMENTED_ExprDict +NOT_YET_IMPLEMENTED_ExprDict +NOT_YET_IMPLEMENTED_ExprDict +NOT_YET_IMPLEMENTED_ExprSet +NOT_YET_IMPLEMENTED_ExprBoolOp +NOT_YET_IMPLEMENTED_ExprTuple +NOT_YET_IMPLEMENTED_ExprTuple +NOT_YET_IMPLEMENTED_ExprTuple +NOT_YET_IMPLEMENTED_ExprTuple [] -[1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)] -[1, 2, 3] -[*a] -[*range(10)] -[*a, 4, 5] -[4, *a, 5] +[ + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + (NOT_YET_IMPLEMENTED_ExprBoolOp), + (NOT_YET_IMPLEMENTED_ExprBoolOp), + (NOT_YET_IMPLEMENTED_ExprBoolOp), +] +[ + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, +] +[NOT_YET_IMPLEMENTED_ExprStarred] +[NOT_YET_IMPLEMENTED_ExprStarred] +[ + NOT_YET_IMPLEMENTED_ExprStarred, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, +] +[ + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprStarred, + NOT_YET_IMPLEMENTED_ExprConstant, +] [ this_is_a_very_long_variable_which_will_force_a_delimiter_split, element, another, - *more, + NOT_YET_IMPLEMENTED_ExprStarred, ] -{i for i in (1, 2, 3)} -{(i ** 2) for i in (1, 2, 3)} -{(i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))} -{((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)} -[i for i in (1, 2, 3)] -[(i ** 2) for i in (1, 2, 3)] -[(i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))] -[((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)] -{i: 0 for i in (1, 2, 3)} -{i: j for i, j in ((1, 'a'), (2, 'b'), (3, 'c'))} -{a: b * 2 for a, b in dictionary.items()} -{a: b * -2 for a, b in dictionary.items()} -{k: v for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension} -Python3 > Python2 > COBOL -Life is Life -call() -call(arg) -call(kwarg='hey') -call(arg, kwarg='hey') -call(arg, another, kwarg='hey', **kwargs) -call(this_is_a_very_long_variable_which_will_force_a_delimiter_split, arg, another, kwarg='hey', **kwargs) # note: no trailing comma pre-3.6 -call(*gidgets[:2]) -call(a, *gidgets[:2]) -call(**self.screen_kwargs) -call(b, **self.screen_kwargs) -lukasz.langa.pl -call.me(maybe) -1 .real -1.0 .real -....__class__ -list[str] -dict[str, int] -tuple[str, ...] -( - tuple[ - str, int, float, dict[str, int] +NOT_YET_IMPLEMENTED_ExprSetComp +NOT_YET_IMPLEMENTED_ExprSetComp +NOT_YET_IMPLEMENTED_ExprSetComp +NOT_YET_IMPLEMENTED_ExprSetComp +NOT_YET_IMPLEMENTED_ExprListComp +NOT_YET_IMPLEMENTED_ExprListComp +NOT_YET_IMPLEMENTED_ExprListComp +NOT_YET_IMPLEMENTED_ExprListComp +NOT_YET_IMPLEMENTED_ExprDictComp +NOT_YET_IMPLEMENTED_ExprDictComp +NOT_YET_IMPLEMENTED_ExprDictComp +NOT_YET_IMPLEMENTED_ExprDictComp +NOT_YET_IMPLEMENTED_ExprDictComp +NOT_YET_IMPLEMENTED_ExprCompare +NOT_YET_IMPLEMENTED_ExprCompare +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_ExprCall # note: no trailing comma pre-3.6 +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_ExprAttribute +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_ExprAttribute +NOT_YET_IMPLEMENTED_ExprAttribute +NOT_YET_IMPLEMENTED_ExprAttribute +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_StmtAnnAssign +NOT_YET_IMPLEMENTED_StmtAnnAssign +NOT_YET_IMPLEMENTED_StmtAnnAssign +NOT_YET_IMPLEMENTED_StmtAnnAssign # type: ignore +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprIfExp +NOT_YET_IMPLEMENTED_ExprDict +NOT_YET_IMPLEMENTED_ExprSet +[ + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprConstant, + NOT_YET_IMPLEMENTED_ExprBoolOp, + NOT_YET_IMPLEMENTED_ExprBoolOp, + NOT_YET_IMPLEMENTED_ExprBoolOp, ] -) -tuple[str, int, float, dict[str, int],] -very_long_variable_name_filters: t.List[ - t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]], -] -xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore - sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) -) -xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore - sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) -) -xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[ - ..., List[SomeClass] -] = classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) # type: ignore -slice[0] -slice[0:1] -slice[0:1:2] -slice[:] -slice[:-1] -slice[1:] -slice[::-1] -slice[d :: d + 1] -slice[:c, c - 1] -numpy[:, 0:1] -numpy[:, :-1] -numpy[0, :] -numpy[:, i] -numpy[0, :2] -numpy[:N, 0] -numpy[:2, :4] -numpy[2:4, 1:5] -numpy[4:, 2:] -numpy[:, (0, 1, 2, 5)] -numpy[0, [0]] -numpy[:, [i]] -numpy[1 : c + 1, c] -numpy[-(c + 1) :, d] -numpy[:, l[-2]] -numpy[:, ::-1] -numpy[np.newaxis, :] -(str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None) -{'2.7': dead, '3.7': long_live or die_hard} -{'2.7', '3.6', '3.7', '3.8', '3.9', '4.0' if gilectomy else '3.10'} -[1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C] (SomeName) SomeName -(Good, Bad, Ugly) -(i for i in (1, 2, 3)) -((i ** 2) for i in (1, 2, 3)) -((i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))) -(((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)) -(*starred,) -{"id": "1","type": "type","started_at": now(),"ended_at": now() + timedelta(days=10),"priority": 1,"import_session_id": 1,**kwargs} -a = (1,) -b = 1, -c = 1 -d = (1,) + a + (2,) -e = (1,).count(1) -f = 1, *range(10) -g = 1, *"ten" -what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(vars_to_remove) -what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(vars_to_remove) -result = session.query(models.Customer.id).filter(models.Customer.account_id == account_id, models.Customer.email == email_address).order_by(models.Customer.id.asc()).all() -result = session.query(models.Customer.id).filter(models.Customer.account_id == account_id, models.Customer.email == email_address).order_by(models.Customer.id.asc(),).all() -Ø = set() -authors.łukasz.say_thanks() -mapping = { - A: 0.25 * (10.0 / 12), - B: 0.1 * (10.0 / 12), - C: 0.1 * (10.0 / 12), - D: 0.1 * (10.0 / 12), -} +NOT_YET_IMPLEMENTED_ExprTuple +NOT_YET_IMPLEMENTED_ExprGeneratorExp +NOT_YET_IMPLEMENTED_ExprGeneratorExp +NOT_YET_IMPLEMENTED_ExprGeneratorExp +NOT_YET_IMPLEMENTED_ExprGeneratorExp +NOT_YET_IMPLEMENTED_ExprTuple +NOT_YET_IMPLEMENTED_ExprDict +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_StmtAssign -def gen(): - yield from outside_of_generator - a = (yield) - b = ((yield)) - c = (((yield))) +NOT_YET_IMPLEMENTED_StmtFunctionDef -async def f(): - await some.complicated[0].call(with_args=(True or (1 is not 1))) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -print(* [] or [1]) -print(**{1: 3} if False else {x: x for x in range(3)}) -print(* lambda x: x) -assert(not Test),("Short message") -assert this is ComplexTest and not requirements.fit_in_a_single_line(force=False), "Short message" -assert(((parens is TooMany))) -for x, in (1,), (2,), (3,): ... -for y in (): ... -for z in (i for i in (1, 2, 3)): ... -for i in (call()): ... -for j in (1 + (2 + 3)): ... -while this and that: - ... -for addr_family, addr_type, addr_proto, addr_canonname, addr_sockaddr in socket.getaddrinfo('google.com', 'http'): - pass -a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz -a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp not in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz -a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp is qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz -a = aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz -if ( - threading.current_thread() != threading.main_thread() and - threading.current_thread() != threading.main_thread() or - signal.getsignal(signal.SIGINT) != signal.default_int_handler -): - return True -if ( - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -): - return True -if ( - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -): - return True -if ( - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -): - return True -if ( - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -): - return True -if ( - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -): - return True -if ( - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa / - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -): - return True -if ( - ~ aaaa.a + aaaa.b - aaaa.c * aaaa.d / aaaa.e | aaaa.f & aaaa.g % aaaa.h ^ aaaa.i << aaaa.k >> aaaa.l ** aaaa.m // aaaa.n -): - return True -if ( - ~ aaaaaaaa.a + aaaaaaaa.b - aaaaaaaa.c @ aaaaaaaa.d / aaaaaaaa.e | aaaaaaaa.f & aaaaaaaa.g % aaaaaaaa.h ^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l ** aaaaaaaa.m // aaaaaaaa.n -): - return True -if ( - ~ aaaaaaaaaaaaaaaa.a + aaaaaaaaaaaaaaaa.b - aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e | aaaaaaaaaaaaaaaa.f & aaaaaaaaaaaaaaaa.g % aaaaaaaaaaaaaaaa.h ^ aaaaaaaaaaaaaaaa.i << aaaaaaaaaaaaaaaa.k >> aaaaaaaaaaaaaaaa.l ** aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n -): - return True +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_ExprCall +NOT_YET_IMPLEMENTED_StmtAssert +NOT_YET_IMPLEMENTED_StmtAssert +NOT_YET_IMPLEMENTED_StmtAssert +NOT_YET_IMPLEMENTED_StmtFor +NOT_YET_IMPLEMENTED_StmtFor +NOT_YET_IMPLEMENTED_StmtFor +NOT_YET_IMPLEMENTED_StmtFor +NOT_YET_IMPLEMENTED_StmtFor +while NOT_YET_IMPLEMENTED_ExprBoolOp: + NOT_YET_IMPLEMENTED_ExprConstant +NOT_YET_IMPLEMENTED_StmtFor +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtIf +NOT_YET_IMPLEMENTED_StmtIf +NOT_YET_IMPLEMENTED_StmtIf +NOT_YET_IMPLEMENTED_StmtIf +NOT_YET_IMPLEMENTED_StmtIf +NOT_YET_IMPLEMENTED_StmtIf +NOT_YET_IMPLEMENTED_StmtIf +NOT_YET_IMPLEMENTED_StmtIf +NOT_YET_IMPLEMENTED_StmtIf +NOT_YET_IMPLEMENTED_StmtIf ( aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa @@ -929,10 +1129,11 @@ aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa bbbb >> bbbb * bbbb ( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - ^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + ^ NOT_YET_IMPLEMENTED_ExprAttribute + & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ) -last_call() +NOT_YET_IMPLEMENTED_ExprCall # standalone comment at ENDMARKER ``` 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 33388de664..1aa29e0f8a 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 @@ -53,46 +53,67 @@ def test_calculate_fades(): ```diff --- Black +++ Ruff -@@ -3,6 +3,7 @@ - TmSt = 1 - TmEx = 2 +@@ -1,40 +1,26 @@ +-import pytest ++NOT_YET_IMPLEMENTED_StmtImport +-TmSt = 1 +-TmEx = 2 ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign + + # fmt: off # Test data: -@@ -18,18 +19,22 @@ - def test_fader(test): - pass + # Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]] +-@pytest.mark.parametrize('test', [ ++NOT_YET_IMPLEMENTED_StmtFunctionDef + - def check_fader(test): - - pass - + - def verify_fader(test): - # misaligned comment - pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef -+ - def verify_fader(test): - """Hey, ho.""" - assert test.passed() +- # Test don't manage the volume +- [ +- ('stuff', 'in') +- ], +-]) +-def test_fader(test): +- pass -+ - def test_calculate_fades(): - calcs = [ - # one is zero/none +-def check_fader(test): ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +- pass + +-def verify_fader(test): +- # misaligned comment +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +-def verify_fader(test): +- """Hey, ho.""" +- assert test.passed() + +-def test_calculate_fades(): +- calcs = [ +- # one is zero/none +- (0, 4, 0, 0, 10, 0, 0, 6, 10), +- (None, 4, 0, 0, 10, 0, 0, 6, 10), +- ] ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + # fmt: on ``` ## Ruff Output ```py -import pytest +NOT_YET_IMPLEMENTED_StmtImport -TmSt = 1 -TmEx = 2 +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign # fmt: off @@ -100,38 +121,19 @@ TmEx = 2 # Test data: # Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]] -@pytest.mark.parametrize('test', [ - - # Test don't manage the volume - [ - ('stuff', 'in') - ], -]) -def test_fader(test): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def check_fader(test): - - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def verify_fader(test): - # misaligned comment - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def verify_fader(test): - """Hey, ho.""" - assert test.passed() +NOT_YET_IMPLEMENTED_StmtFunctionDef -def test_calculate_fades(): - calcs = [ - # one is zero/none - (0, 4, 0, 0, 10, 0, 0, 6, 10), - (None, 4, 0, 0, 10, 0, 0, 6, 10), - ] +NOT_YET_IMPLEMENTED_StmtFunctionDef # fmt: on ``` diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff3_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff3_py.snap index 772a2828ad..b732da7560 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff3_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff3_py.snap @@ -30,36 +30,39 @@ x = [ ```diff --- Black +++ Ruff -@@ -12,4 +12,6 @@ - ] +@@ -1,15 +1,9 @@ + # fmt: off +-x = [ +- 1, 2, +- 3, 4, +-] ++NOT_YET_IMPLEMENTED_StmtAssign + # fmt: on + + # fmt: off +-x = [ +- 1, 2, +- 3, 4, +-] ++NOT_YET_IMPLEMENTED_StmtAssign # fmt: on -x = [1, 2, 3, 4] -+x = [ -+ 1, 2, 3, 4 -+] ++NOT_YET_IMPLEMENTED_StmtAssign ``` ## Ruff Output ```py # fmt: off -x = [ - 1, 2, - 3, 4, -] +NOT_YET_IMPLEMENTED_StmtAssign # fmt: on # fmt: off -x = [ - 1, 2, - 3, 4, -] +NOT_YET_IMPLEMENTED_StmtAssign # fmt: on -x = [ - 1, 2, 3, 4 -] +NOT_YET_IMPLEMENTED_StmtAssign ``` ## Black Output 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 4c768c3d7d..6deb07e816 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 @@ -26,13 +26,16 @@ def f(): pass ```diff --- Black +++ Ruff -@@ -4,17 +4,11 @@ - 3, 4, - ]) - # fmt: on +@@ -1,20 +1,5 @@ + # fmt: off +-@test([ +- 1, 2, +- 3, 4, +-]) +-# fmt: on -def f(): - pass -+def f(): pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef -@test( @@ -45,30 +48,17 @@ def f(): pass -) -def f(): - pass -+@test([ -+ 1, 2, -+ 3, 4, -+]) -+def f(): pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Ruff Output ```py # fmt: off -@test([ - 1, 2, - 3, 4, -]) -# fmt: on -def f(): pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -@test([ - 1, 2, - 3, 4, -]) -def f(): pass +NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## 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 0355c63528..b01fb338f6 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 @@ -97,133 +97,136 @@ elif unformatted: ```diff --- Black +++ Ruff -@@ -44,7 +44,7 @@ - print ( "This won't be formatted" ) - print ( "This won't be formatted either" ) - else: +@@ -1,87 +1,29 @@ + # Regression test for https://github.com/psf/black/issues/3129. +-setup( +- entry_points={ +- # fmt: off +- "console_scripts": [ +- "foo-bar" +- "=foo.bar.:main", +- # fmt: on +- ] # Includes an formatted indentation. +- }, +-) ++NOT_YET_IMPLEMENTED_ExprCall + + + # Regression test for https://github.com/psf/black/issues/2015. +-run( +- # fmt: off +- [ +- "ls", +- "-la", +- ] +- # fmt: on +- + path, +- check=True, +-) ++NOT_YET_IMPLEMENTED_ExprCall + + + # Regression test for https://github.com/psf/black/issues/3026. +-def test_func(): +- # yapf: disable +- if unformatted( args ): +- return True +- # yapf: enable +- elif b: +- return True ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +- return False + +- + # Regression test for https://github.com/psf/black/issues/2567. +-if True: +- # fmt: off +- for _ in range( 1 ): +- # fmt: on +- print ( "This won't be formatted" ) +- print ( "This won't be formatted either" ) +-else: - print("This will be formatted") -+ print ( "This will be formatted" ) ++NOT_YET_IMPLEMENTED_StmtIf # Regression test for https://github.com/psf/black/issues/3184. -@@ -61,7 +61,7 @@ - elif param[0:4] in ("ZZZZ",): - print ( "This won't be formatted either" ) - +-class A: +- async def call(param): +- if param: +- # fmt: off +- if param[0:4] in ( +- "ABCD", "EFGH" +- ) : +- # 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") -+ print ( "This will be formatted" ) ++NOT_YET_IMPLEMENTED_StmtClassDef # Regression test for https://github.com/psf/black/issues/2985. -@@ -72,10 +72,7 @@ +-class Named(t.Protocol): +- # fmt: off +- @property +- def this_wont_be_formatted ( self ) -> str: ... ++NOT_YET_IMPLEMENTED_StmtClassDef - class Factory(t.Protocol): +-class Factory(t.Protocol): - def this_will_be_formatted(self, **kwargs) -> Named: - ... -- -- # fmt: on -+ def this_will_be_formatted ( self, **kwargs ) -> Named: ... ++NOT_YET_IMPLEMENTED_StmtClassDef +- # fmt: on +- # Regression test for https://github.com/psf/black/issues/3436. -@@ -83,5 +80,5 @@ - return x - # fmt: off - elif unformatted: +-if x: +- return x +-# fmt: off +-elif unformatted: - # fmt: on - will_be_formatted() -+# fmt: on -+ will_be_formatted () ++NOT_YET_IMPLEMENTED_StmtIf ``` ## Ruff Output ```py # Regression test for https://github.com/psf/black/issues/3129. -setup( - entry_points={ - # fmt: off - "console_scripts": [ - "foo-bar" - "=foo.bar.:main", - # fmt: on - ] # Includes an formatted indentation. - }, -) +NOT_YET_IMPLEMENTED_ExprCall # Regression test for https://github.com/psf/black/issues/2015. -run( - # fmt: off - [ - "ls", - "-la", - ] - # fmt: on - + path, - check=True, -) +NOT_YET_IMPLEMENTED_ExprCall # Regression test for https://github.com/psf/black/issues/3026. -def test_func(): - # yapf: disable - if unformatted( args ): - return True - # yapf: enable - elif b: - return True - - return False +NOT_YET_IMPLEMENTED_StmtFunctionDef # Regression test for https://github.com/psf/black/issues/2567. -if True: - # fmt: off - for _ in range( 1 ): - # fmt: on - print ( "This won't be formatted" ) - print ( "This won't be formatted either" ) -else: - print ( "This will be formatted" ) +NOT_YET_IMPLEMENTED_StmtIf # Regression test for https://github.com/psf/black/issues/3184. -class A: - async def call(param): - if param: - # fmt: off - if param[0:4] in ( - "ABCD", "EFGH" - ) : - # 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 # Regression test for https://github.com/psf/black/issues/2985. -class Named(t.Protocol): - # fmt: off - @property - def this_wont_be_formatted ( self ) -> str: ... +NOT_YET_IMPLEMENTED_StmtClassDef -class Factory(t.Protocol): - def this_will_be_formatted ( self, **kwargs ) -> Named: ... +NOT_YET_IMPLEMENTED_StmtClassDef # Regression test for https://github.com/psf/black/issues/3436. -if x: - return x -# fmt: off -elif unformatted: -# fmt: on - will_be_formatted () +NOT_YET_IMPLEMENTED_StmtIf ``` ## Black Output 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 71c0fceef3..6b67c58b5d 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 @@ -199,58 +199,60 @@ d={'a':1, ```diff --- Black +++ Ruff -@@ -4,17 +4,18 @@ +@@ -1,224 +1,73 @@ + #!/usr/bin/env python3 +-import asyncio +-import sys ++NOT_YET_IMPLEMENTED_StmtImport ++NOT_YET_IMPLEMENTED_StmtImport - from third_party import X, Y, Z +-from third_party import X, Y, Z ++NOT_YET_IMPLEMENTED_StmtImportFrom -from library import some_connection, some_decorator - -+from library import some_connection, \ -+ some_decorator ++NOT_YET_IMPLEMENTED_StmtImportFrom # fmt: off - from third_party import (X, - Y, Z) +-from third_party import (X, +- Y, Z) ++NOT_YET_IMPLEMENTED_StmtImportFrom # fmt: on -f"trigger 3.6 mode" -+f'trigger 3.6 mode' ++NOT_YET_IMPLEMENTED_ExprJoinedStr + + # Comment 1 # Comment 2 -- +- # fmt: off - def func_no_args(): -@@ -26,11 +27,15 @@ - continue - exec('new-style exec', {}, {}) - return None -+ -+ - async def coroutine(arg, exec=False): - 'Single-line docstring. Multiline is harder to reformat.' - async with some_connection() as conn: - await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2) - await asyncio.sleep(1) -+ -+ - @asyncio.coroutine - @some_decorator( - with_args=True, -@@ -38,28 +43,19 @@ - ) - def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str: - return text[number:-1] -+ -+ - # fmt: on +-def func_no_args(): +- a; b; c +- if True: raise RuntimeError +- if False: ... +- for i in range(10): +- print(i) +- continue +- exec('new-style exec', {}, {}) +- return None +-async def coroutine(arg, exec=False): +- 'Single-line docstring. Multiline is harder to reformat.' +- async with some_connection() as conn: +- await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2) +- await asyncio.sleep(1) +-@asyncio.coroutine +-@some_decorator( +-with_args=True, +-many_args=[1,2,3] +-) +-def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str: +- return text[number:-1] +-# fmt: on -def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""): - offset = attr.ib(default=attr.Factory(lambda: _r.uniform(1, 2))) - assert task._cancel_stack[: len(old_stack)] == old_stack -+def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''): -+ offset = attr.ib(default=attr.Factory( lambda: _r.uniform(1, 2))) -+ assert task._cancel_stack[:len(old_stack)] == old_stack ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def spaces_types( @@ -265,115 +267,162 @@ d={'a':1, - i: str = r"", -): - ... -+def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ... ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -def spaces2(result=_core.Value(None)): - ... -+def spaces2(result= _core.Value(None)): -+ ... ++NOT_YET_IMPLEMENTED_StmtFunctionDef - something = { -@@ -74,23 +70,20 @@ - 'some big and', - 'complex subscript', - # fmt: on +-something = { +- # fmt: off +- key: 'value', +-} ++# fmt: on ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-def subscriptlist(): +- atom[ +- # fmt: off +- 'some big and', +- 'complex subscript', +- # fmt: on - goes + here, - andhere, - ] -+ goes + here, andhere, -+ ] ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def import_as_names(): - # fmt: off - from hello import a, b - 'unformatted' +-def import_as_names(): +- # fmt: off +- from hello import a, b +- 'unformatted' - # fmt: on ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def testlist_star_expr(): - # fmt: off - a , b = *hello - 'unformatted' +-def testlist_star_expr(): +- # fmt: off +- a , b = *hello +- 'unformatted' - # fmt: on ++NOT_YET_IMPLEMENTED_StmtAssign - def yield_expr(): -@@ -98,11 +91,10 @@ - yield hello - 'unformatted' - # fmt: on +-def yield_expr(): +- # fmt: off +- yield hello +- 'unformatted' +- # fmt: on - "formatted" -+ 'formatted' - # fmt: off - ( yield hello ) - 'unformatted' +- # fmt: off +- ( yield hello ) +- 'unformatted' - # fmt: on ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def example(session): -@@ -113,7 +105,6 @@ - models.Customer.email == email_address)\ - .order_by(models.Customer.id.asc())\ - .all() +-def example(session): +- # fmt: off +- result = session\ +- .query(models.Customer.id)\ +- .filter(models.Customer.account_id == account_id, +- models.Customer.email == email_address)\ +- .order_by(models.Customer.id.asc())\ +- .all() - # fmt: on ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def off_and_on_without_data(): -@@ -123,8 +114,10 @@ - """ - # fmt: off +-def off_and_on_without_data(): +- """All comments here are technically on the same prefix. ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +- The comments between will be formatted. This is a known limitation. +- """ +- # fmt: off - # hey, that won't work ++NOT_YET_IMPLEMENTED_StmtFunctionDef -+ #hey, that won't work -+ -+ - # fmt: on - pass +- # fmt: on +- pass -@@ -137,21 +130,12 @@ - and_=indeed . it is not formatted - because . the . handling . inside . generate_ignored_nodes() - now . considers . multiple . fmt . directives . within . one . prefix ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +-def on_and_off_broken(): +- """Another known limitation.""" +- # fmt: on +- # fmt: off +- this=should.not_be.formatted() +- and_=indeed . it is not formatted +- because . the . handling . inside . generate_ignored_nodes() +- now . considers . multiple . fmt . directives . within . one . prefix - # fmt: on - # fmt: off - # ...but comments still get reformatted even though they should not be - # fmt: on ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def long_lines(): - if True: - typedargslist.extend( +-def long_lines(): +- if True: +- typedargslist.extend( - gen_annotated_params( - ast_args.kwonlyargs, - ast_args.kw_defaults, - parameters, - implicit_default=True, - ) -+ gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True) - ) - # fmt: off - a = ( -@@ -186,20 +170,19 @@ +- ) +- # fmt: off +- a = ( +- unnecessary_bracket() +- ) +- # fmt: on +- _type_comment_re = re.compile( +- r""" +- ^ +- [\t ]* +- \#[ ]type:[ ]* +- (?P +- [^#\t\n]+? +- ) +- (? to match +- # a trailing space which is why we need the silliness below +- (? +- (?:\#[^\n]*)? +- \n? +- ) +- $ +- """, +- # fmt: off +- re.MULTILINE|re.VERBOSE +- # fmt: on +- ) - def single_literal_yapf_disable(): - """Black does not support this.""" ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +-def single_literal_yapf_disable(): +- """Black does not support this.""" - BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)} # yapf: disable -+ BAZ = { -+ (1, 2, 3, 4), -+ (5, 6, 7, 8), -+ (9, 10, 11, 12) -+ } ++NOT_YET_IMPLEMENTED_StmtFunctionDef ++ ++ ++NOT_YET_IMPLEMENTED_StmtFunctionDef ++ - cfg.rule( +-cfg.rule( - "Default", - "address", -+ "Default", "address", - xxxx_xxxx=["xxx-xxxxxx-xxxxxxxxxx"], +- xxxx_xxxx=["xxx-xxxxxx-xxxxxxxxxx"], - xxxxxx="xx_xxxxx", - xxxxxxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - xxxxxxxxx_xxxx=True, @@ -381,39 +430,48 @@ d={'a':1, - xxxxxx_xxxxxx=2, - xxxxxx_xxxxx_xxxxxxxx=70, - xxxxxx_xxxxxx_xxxxx=True, -+ xxxxxx="xx_xxxxx", xxxxxxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", -+ xxxxxxxxx_xxxx=True, xxxxxxxx_xxxxxxxxxx=False, -+ xxxxxx_xxxxxx=2, xxxxxx_xxxxx_xxxxxxxx=70, xxxxxx_xxxxxx_xxxxx=True, - # fmt: off - xxxxxxx_xxxxxxxxxxxx={ - "xxxxxxxx": { -@@ -214,7 +197,7 @@ - }, - }, - # fmt: on +- # fmt: off +- xxxxxxx_xxxxxxxxxxxx={ +- "xxxxxxxx": { +- "xxxxxx": False, +- "xxxxxxx": False, +- "xxxx_xxxxxx": "xxxxx", +- }, +- "xxxxxxxx-xxxxx": { +- "xxxxxx": False, +- "xxxxxxx": True, +- "xxxx_xxxxxx": "xxxxxx", +- }, +- }, +- # fmt: on - xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5, -+ xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5 - ) +-) ++NOT_YET_IMPLEMENTED_ExprCall # fmt: off - yield 'hello' +-yield 'hello' ++NOT_YET_IMPLEMENTED_ExprYield + # No formatting to the end of the file +-l=[1,2,3] +-d={'a':1, +- 'b':2} ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ``` ## Ruff Output ```py #!/usr/bin/env python3 -import asyncio -import sys +NOT_YET_IMPLEMENTED_StmtImport +NOT_YET_IMPLEMENTED_StmtImport -from third_party import X, Y, Z +NOT_YET_IMPLEMENTED_StmtImportFrom -from library import some_connection, \ - some_decorator +NOT_YET_IMPLEMENTED_StmtImportFrom # fmt: off -from third_party import (X, - Y, Z) +NOT_YET_IMPLEMENTED_StmtImportFrom # fmt: on -f'trigger 3.6 mode' +NOT_YET_IMPLEMENTED_ExprJoinedStr # Comment 1 @@ -421,193 +479,61 @@ f'trigger 3.6 mode' # Comment 2 # fmt: off -def func_no_args(): - a; b; c - if True: raise RuntimeError - if False: ... - for i in range(10): - print(i) - continue - exec('new-style exec', {}, {}) - return None +NOT_YET_IMPLEMENTED_StmtFunctionDef -async def coroutine(arg, exec=False): - 'Single-line docstring. Multiline is harder to reformat.' - async with some_connection() as conn: - await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2) - await asyncio.sleep(1) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -@asyncio.coroutine -@some_decorator( -with_args=True, -many_args=[1,2,3] -) -def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str: - return text[number:-1] +NOT_YET_IMPLEMENTED_StmtFunctionDef # fmt: on -def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''): - offset = attr.ib(default=attr.Factory( lambda: _r.uniform(1, 2))) - assert task._cancel_stack[:len(old_stack)] == old_stack +NOT_YET_IMPLEMENTED_StmtFunctionDef -def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ... +NOT_YET_IMPLEMENTED_StmtFunctionDef -def spaces2(result= _core.Value(None)): - ... +NOT_YET_IMPLEMENTED_StmtFunctionDef -something = { - # fmt: off - key: 'value', -} +NOT_YET_IMPLEMENTED_StmtAssign -def subscriptlist(): - atom[ - # fmt: off - 'some big and', - 'complex subscript', - # fmt: on - goes + here, andhere, - ] +NOT_YET_IMPLEMENTED_StmtFunctionDef -def import_as_names(): - # fmt: off - from hello import a, b - 'unformatted' +NOT_YET_IMPLEMENTED_StmtFunctionDef -def testlist_star_expr(): - # fmt: off - a , b = *hello - 'unformatted' +NOT_YET_IMPLEMENTED_StmtFunctionDef -def yield_expr(): - # fmt: off - yield hello - 'unformatted' - # fmt: on - 'formatted' - # fmt: off - ( yield hello ) - 'unformatted' +NOT_YET_IMPLEMENTED_StmtFunctionDef -def example(session): - # fmt: off - result = session\ - .query(models.Customer.id)\ - .filter(models.Customer.account_id == account_id, - models.Customer.email == email_address)\ - .order_by(models.Customer.id.asc())\ - .all() +NOT_YET_IMPLEMENTED_StmtFunctionDef -def off_and_on_without_data(): - """All comments here are technically on the same prefix. - - The comments between will be formatted. This is a known limitation. - """ - # fmt: off +NOT_YET_IMPLEMENTED_StmtFunctionDef - #hey, that won't work +NOT_YET_IMPLEMENTED_StmtFunctionDef - # fmt: on - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def on_and_off_broken(): - """Another known limitation.""" - # fmt: on - # fmt: off - this=should.not_be.formatted() - and_=indeed . it is not formatted - because . the . handling . inside . generate_ignored_nodes() - now . considers . multiple . fmt . directives . within . one . prefix +NOT_YET_IMPLEMENTED_StmtFunctionDef -def long_lines(): - if True: - typedargslist.extend( - gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True) - ) - # fmt: off - a = ( - unnecessary_bracket() - ) - # fmt: on - _type_comment_re = re.compile( - r""" - ^ - [\t ]* - \#[ ]type:[ ]* - (?P - [^#\t\n]+? - ) - (? to match - # a trailing space which is why we need the silliness below - (? - (?:\#[^\n]*)? - \n? - ) - $ - """, - # fmt: off - re.MULTILINE|re.VERBOSE - # fmt: on - ) - - -def single_literal_yapf_disable(): - """Black does not support this.""" - BAZ = { - (1, 2, 3, 4), - (5, 6, 7, 8), - (9, 10, 11, 12) - } - - -cfg.rule( - "Default", "address", - xxxx_xxxx=["xxx-xxxxxx-xxxxxxxxxx"], - xxxxxx="xx_xxxxx", xxxxxxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - xxxxxxxxx_xxxx=True, xxxxxxxx_xxxxxxxxxx=False, - xxxxxx_xxxxxx=2, xxxxxx_xxxxx_xxxxxxxx=70, xxxxxx_xxxxxx_xxxxx=True, - # fmt: off - xxxxxxx_xxxxxxxxxxxx={ - "xxxxxxxx": { - "xxxxxx": False, - "xxxxxxx": False, - "xxxx_xxxxxx": "xxxxx", - }, - "xxxxxxxx-xxxxx": { - "xxxxxx": False, - "xxxxxxx": True, - "xxxx_xxxxxx": "xxxxxx", - }, - }, - # fmt: on - xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5 -) +NOT_YET_IMPLEMENTED_ExprCall # fmt: off -yield 'hello' +NOT_YET_IMPLEMENTED_ExprYield # No formatting to the end of the file -l=[1,2,3] -d={'a':1, - 'b':2} +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip2_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip2_py.snap index 99d137293e..91d954035a 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip2_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip2_py.snap @@ -22,22 +22,23 @@ l3 = ["I have", "trailing comma", "so I should be braked",] - "into multiple lines", - "because it is way too long", -] -+l1 = ["This list should be broken up", "into multiple lines", "because it is way too long"] - l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip +-l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip -l3 = [ - "I have", - "trailing comma", - "so I should be braked", -] -+l3 = ["I have", "trailing comma", "so I should be braked",] ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip ++NOT_YET_IMPLEMENTED_StmtAssign ``` ## Ruff Output ```py -l1 = ["This list should be broken up", "into multiple lines", "because it is way too long"] -l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip -l3 = ["I have", "trailing comma", "so I should be braked",] +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip +NOT_YET_IMPLEMENTED_StmtAssign ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip3_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip3_py.snap index 6dd878bc1e..afe9c07c06 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip3_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip3_py.snap @@ -22,29 +22,32 @@ f = ["This is a very long line that should be formatted into a clearer line ", " +++ Ruff @@ -1,10 +1,7 @@ -a = 3 -+a = 3 ++NOT_YET_IMPLEMENTED_StmtAssign # fmt: off - b, c = 1, 2 - d = 6 # fmt: skip - e = 5 +-b, c = 1, 2 +-d = 6 # fmt: skip +-e = 5 ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip ++NOT_YET_IMPLEMENTED_StmtAssign # fmt: on -f = [ - "This is a very long line that should be formatted into a clearer line ", - "by rearranging.", -] -+f = ["This is a very long line that should be formatted into a clearer line ", "by rearranging."] ++NOT_YET_IMPLEMENTED_StmtAssign ``` ## Ruff Output ```py -a = 3 +NOT_YET_IMPLEMENTED_StmtAssign # fmt: off -b, c = 1, 2 -d = 6 # fmt: skip -e = 5 +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip +NOT_YET_IMPLEMENTED_StmtAssign # fmt: on -f = ["This is a very long line that should be formatted into a clearer line ", "by rearranging."] +NOT_YET_IMPLEMENTED_StmtAssign ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip4_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip4_py.snap index 745448d84d..a1c0e29da9 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip4_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip4_py.snap @@ -18,22 +18,22 @@ l = [1, 2, 3,] +++ Ruff @@ -1,7 +1,3 @@ -a = 2 -+a = 2 ++NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip -l = [ - 1, - 2, - 3, -] -+l = [1, 2, 3,] ++NOT_YET_IMPLEMENTED_StmtAssign ``` ## Ruff Output ```py -a = 2 +NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip -l = [1, 2, 3,] +NOT_YET_IMPLEMENTED_StmtAssign ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip5_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip5_py.snap index 99b717aa89..e371421151 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip5_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip5_py.snap @@ -22,29 +22,25 @@ else: ```diff --- Black +++ Ruff -@@ -1,6 +1,6 @@ +@@ -1,9 +1,2 @@ -a, b, c = 3, 4, 5 -+a, b, c = 3, 4, 5 - if ( +-if ( - a == 3 -+ a == 3 - and b != 9 # fmt: skip - and c is not None - ): +- and b != 9 # fmt: skip +- and c is not None +-): +- print("I'm good!") +-else: +- print("I'm bad") ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtIf ``` ## Ruff Output ```py -a, b, c = 3, 4, 5 -if ( - a == 3 - and b != 9 # fmt: skip - and c is not None -): - print("I'm good!") -else: - print("I'm bad") +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtIf ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip6_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip6_py.snap index 46b8920531..ea2bbeca77 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip6_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip6_py.snap @@ -18,22 +18,19 @@ class A: ```diff --- Black +++ Ruff -@@ -2,4 +2,4 @@ - def f(self): - for line in range(10): - if True: +@@ -1,5 +1 @@ +-class A: +- def f(self): +- for line in range(10): +- if True: - pass # fmt: skip -+ pass ++NOT_YET_IMPLEMENTED_StmtClassDef ``` ## Ruff Output ```py -class A: - def f(self): - for line in range(10): - if True: - pass +NOT_YET_IMPLEMENTED_StmtClassDef ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip7_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip7_py.snap index 57059c0919..976f778505 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip7_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip7_py.snap @@ -19,19 +19,22 @@ d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasu +++ Ruff @@ -1,4 +1,4 @@ -a = "this is some code" -+a = "this is some code" - b = 5 # fmt:skip - c = 9 # fmt: skip - d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip +-b = 5 # fmt:skip +-c = 9 # fmt: skip +-d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign # fmt:skip ++NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip ++NOT_YET_IMPLEMENTED_StmtAssign # fmt:skip ``` ## Ruff Output ```py -a = "this is some code" -b = 5 # fmt:skip -c = 9 # fmt: skip -d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign # fmt:skip +NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip +NOT_YET_IMPLEMENTED_StmtAssign # fmt:skip ``` ## Black Output 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 0ebe890404..ef64a5e6ef 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 @@ -75,108 +75,118 @@ async def test_async_with(): ```diff --- Black +++ Ruff -@@ -2,7 +2,6 @@ - def some_func( unformatted, args ): # fmt: skip - print("I am some_func") - return 0 +@@ -1,62 +1,33 @@ + # Make sure a leading comment is not removed. +-def some_func( unformatted, args ): # fmt: skip +- print("I am some_func") +- return 0 - # Make sure this comment is not removed. ++NOT_YET_IMPLEMENTED_StmtFunctionDef # Make sure a leading comment is not removed. -@@ -29,15 +28,15 @@ - elif another_unformatted_call( args ): # fmt: skip - print("Second branch") - else : # fmt: skip +-async def some_async_func( unformatted, args): # fmt: skip +- print("I am some_async_func") +- await asyncio.sleep(1) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef + + + # Make sure a leading comment is not removed. +-class SomeClass( Unformatted, SuperClasses ): # fmt: skip +- 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) + +- + # Make sure a leading comment is not removed. +-if unformatted_call( args ): # fmt: skip +- print("First branch") +- # Make sure this is not removed. +-elif another_unformatted_call( args ): # fmt: skip +- print("Second branch") +-else : # fmt: skip - print("Last branch") -+ print("Last branch") # fmt: skip ++NOT_YET_IMPLEMENTED_StmtIf # fmt: skip -while some_condition( unformatted, args ): # fmt: skip -+while some_condition( unformatted, args ): # fmt: skip - print("Do something") - - - for i in some_iter( unformatted, args ): # fmt: skip - print("Do something") -+ print("Do something") # fmt: skip ++while NOT_YET_IMPLEMENTED_ExprCall: # fmt: skip ++ NOT_YET_IMPLEMENTED_ExprCall - async def test_async_for(): -@@ -54,7 +53,7 @@ - - - with give_me_context( unformatted, args ): # fmt: skip +-for i in some_iter( unformatted, args ): # fmt: skip - print("Do something") -+ print("Do something") # fmt: skip ++NOT_YET_IMPLEMENTED_StmtFor # fmt: skip - async def test_async_with(): +-async def test_async_for(): +- async for i in some_async_iter( unformatted, args ): # fmt: skip +- print("Do something") ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef + + +-try : # fmt: skip +- some_call() +-except UnformattedError as ex: # fmt: skip +- handle_exception() +-finally : # fmt: skip +- finally_call() ++NOT_YET_IMPLEMENTED_StmtTry + + +-with give_me_context( unformatted, args ): # fmt: skip +- print("Do something") ++NOT_YET_IMPLEMENTED_StmtWith # fmt: skip + + +-async def test_async_with(): +- async with give_me_async_context( unformatted, args ): # fmt: skip +- print("Do something") ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef ``` ## Ruff Output ```py # Make sure a leading comment is not removed. -def some_func( unformatted, args ): # fmt: skip - print("I am some_func") - return 0 +NOT_YET_IMPLEMENTED_StmtFunctionDef # Make sure a leading comment is not removed. -async def some_async_func( unformatted, args): # fmt: skip - print("I am some_async_func") - await asyncio.sleep(1) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Make sure a leading comment is not removed. -class SomeClass( Unformatted, SuperClasses ): # fmt: skip - def some_method( self, unformatted, args ): # fmt: skip - print("I am some_method") - return 0 - - 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") - # Make sure this is not removed. -elif another_unformatted_call( args ): # fmt: skip - print("Second branch") -else : # fmt: skip - print("Last branch") # fmt: skip +NOT_YET_IMPLEMENTED_StmtIf # fmt: skip -while some_condition( unformatted, args ): # fmt: skip - print("Do something") +while NOT_YET_IMPLEMENTED_ExprCall: # fmt: skip + NOT_YET_IMPLEMENTED_ExprCall -for i in some_iter( unformatted, args ): # fmt: skip - print("Do something") # fmt: skip +NOT_YET_IMPLEMENTED_StmtFor # fmt: skip -async def test_async_for(): - async for i in some_async_iter( unformatted, args ): # fmt: skip - print("Do something") +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -try : # fmt: skip - some_call() -except UnformattedError as ex: # fmt: skip - handle_exception() -finally : # fmt: skip - finally_call() +NOT_YET_IMPLEMENTED_StmtTry -with give_me_context( unformatted, args ): # fmt: skip - print("Do something") # fmt: skip +NOT_YET_IMPLEMENTED_StmtWith # fmt: skip -async def test_async_with(): - async with give_me_async_context( unformatted, args ): # fmt: skip - print("Do something") +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip_py.snap new file mode 100644 index 0000000000..83514e6333 --- /dev/null +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip_py.snap @@ -0,0 +1,44 @@ +--- +source: crates/ruff_python_formatter/src/lib.rs +expression: snapshot +input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip.py +--- +## Input + +```py +a, b = 1, 2 +c = 6 # fmt: skip +d = 5 +``` + +## Black Differences + +```diff +--- Black ++++ Ruff +@@ -1,3 +1,3 @@ +-a, b = 1, 2 +-c = 6 # fmt: skip +-d = 5 ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip ++NOT_YET_IMPLEMENTED_StmtAssign +``` + +## Ruff Output + +```py +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip +NOT_YET_IMPLEMENTED_StmtAssign +``` + +## Black Output + +```py +a, b = 1, 2 +c = 6 # fmt: skip +d = 5 +``` + + diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fstring_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fstring_py.snap index 7dd7584af5..d442a2cf0f 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fstring_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fstring_py.snap @@ -22,28 +22,39 @@ f'Hello \'{tricky + "example"}\'' ```diff --- Black +++ Ruff -@@ -1,6 +1,6 @@ - f"f-string without formatted values is just a string" - f"{{NOT a formatted value}}" +@@ -1,9 +1,9 @@ +-f"f-string without formatted values is just a string" +-f"{{NOT a formatted value}}" -f'{{NOT \'a\' "formatted" "value"}}' -+f"{{NOT 'a' \"formatted\" \"value\"}}" - f"some f-string with {a} {few():.2f} {formatted.values!r}" - f'some f-string with {a} {few(""):.2f} {formatted.values!r}' - f"{f'''{'nested'} inner'''} outer" +-f"some f-string with {a} {few():.2f} {formatted.values!r}" +-f'some f-string with {a} {few(""):.2f} {formatted.values!r}' +-f"{f'''{'nested'} inner'''} outer" +-f"\"{f'{nested} inner'}\" outer" +-f"space between opening braces: { {a for a in (1, 2, 3)}}" +-f'Hello \'{tricky + "example"}\'' ++NOT_YET_IMPLEMENTED_ExprJoinedStr ++NOT_YET_IMPLEMENTED_ExprJoinedStr ++NOT_YET_IMPLEMENTED_ExprJoinedStr ++NOT_YET_IMPLEMENTED_ExprJoinedStr ++NOT_YET_IMPLEMENTED_ExprJoinedStr ++NOT_YET_IMPLEMENTED_ExprJoinedStr ++NOT_YET_IMPLEMENTED_ExprJoinedStr ++NOT_YET_IMPLEMENTED_ExprJoinedStr ++NOT_YET_IMPLEMENTED_ExprJoinedStr ``` ## Ruff Output ```py -f"f-string without formatted values is just a string" -f"{{NOT a formatted value}}" -f"{{NOT 'a' \"formatted\" \"value\"}}" -f"some f-string with {a} {few():.2f} {formatted.values!r}" -f'some f-string with {a} {few(""):.2f} {formatted.values!r}' -f"{f'''{'nested'} inner'''} outer" -f"\"{f'{nested} inner'}\" outer" -f"space between opening braces: { {a for a in (1, 2, 3)}}" -f'Hello \'{tricky + "example"}\'' +NOT_YET_IMPLEMENTED_ExprJoinedStr +NOT_YET_IMPLEMENTED_ExprJoinedStr +NOT_YET_IMPLEMENTED_ExprJoinedStr +NOT_YET_IMPLEMENTED_ExprJoinedStr +NOT_YET_IMPLEMENTED_ExprJoinedStr +NOT_YET_IMPLEMENTED_ExprJoinedStr +NOT_YET_IMPLEMENTED_ExprJoinedStr +NOT_YET_IMPLEMENTED_ExprJoinedStr +NOT_YET_IMPLEMENTED_ExprJoinedStr ``` ## Black Output 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 1a6c83f39e..7222c21c5e 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 @@ -66,128 +66,94 @@ with hmm_but_this_should_get_two_preceding_newlines(): ```diff --- Black +++ Ruff -@@ -1,11 +1,11 @@ - def f( +@@ -1,65 +1,12 @@ +-def f( - a, - **kwargs, -+ a, -+ **kwargs, - ) -> A: - with cache_dir(): - if something: +-) -> A: +- with cache_dir(): +- if something: - result = CliRunner().invoke( - black.main, [str(src1), str(src2), "--diff", "--check"] -+ result = ( -+ CliRunner().invoke(black.main, [str(src1), str(src2), "--diff", "--check"]) - ) - limited.append(-limited.pop()) # negate top - return A( -@@ -17,30 +17,24 @@ - - def g(): - "Docstring." +- ) +- limited.append(-limited.pop()) # negate top +- return A( +- very_long_argument_name1=very_long_value_for_the_argument, +- very_long_argument_name2=-very.long.value.for_the_argument, +- **kwargs, +- ) - - def inner(): - pass - - print("Inner defs should breathe a little.") - - - def h(): - def inner(): - pass +-def g(): +- "Docstring." - - print("Inner defs should breathe a little.") - - - if os.name == "posix": - import termios +- def inner(): +- pass - - def i_should_be_followed_by_only_one_newline(): - pass +- print("Inner defs should breathe a little.") - - elif os.name == "nt": - try: - import msvcrt - - def i_should_be_followed_by_only_one_newline(): - pass +-def h(): +- def inner(): +- pass +- +- print("Inner defs should breathe a little.") +- +- +-if os.name == "posix": +- import termios +- +- def i_should_be_followed_by_only_one_newline(): +- pass +- +-elif os.name == "nt": +- try: +- import msvcrt +- +- def i_should_be_followed_by_only_one_newline(): +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef -@@ -54,12 +48,10 @@ - class IHopeYouAreHavingALovelyDay: - def __call__(self): - print("i_should_be_followed_by_only_one_newline") -- - else: +- except ImportError: - def foo(): - pass +- def i_should_be_followed_by_only_one_newline(): +- pass - +-elif False: ++NOT_YET_IMPLEMENTED_StmtFunctionDef - with hmm_but_this_should_get_two_preceding_newlines(): - pass +- class IHopeYouAreHavingALovelyDay: +- def __call__(self): +- print("i_should_be_followed_by_only_one_newline") + +-else: ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +- def foo(): +- pass + ++NOT_YET_IMPLEMENTED_StmtIf + +-with hmm_but_this_should_get_two_preceding_newlines(): +- pass ++NOT_YET_IMPLEMENTED_StmtWith ``` ## Ruff Output ```py -def f( - a, - **kwargs, -) -> A: - with cache_dir(): - if something: - result = ( - CliRunner().invoke(black.main, [str(src1), str(src2), "--diff", "--check"]) - ) - limited.append(-limited.pop()) # negate top - return A( - very_long_argument_name1=very_long_value_for_the_argument, - very_long_argument_name2=-very.long.value.for_the_argument, - **kwargs, - ) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def g(): - "Docstring." - def inner(): - pass - print("Inner defs should breathe a little.") +NOT_YET_IMPLEMENTED_StmtFunctionDef -def h(): - def inner(): - pass - print("Inner defs should breathe a little.") +NOT_YET_IMPLEMENTED_StmtFunctionDef -if os.name == "posix": - import termios - def i_should_be_followed_by_only_one_newline(): - pass -elif os.name == "nt": - try: - import msvcrt - def i_should_be_followed_by_only_one_newline(): - pass +NOT_YET_IMPLEMENTED_StmtIf - except ImportError: - - def i_should_be_followed_by_only_one_newline(): - pass - -elif False: - - class IHopeYouAreHavingALovelyDay: - def __call__(self): - print("i_should_be_followed_by_only_one_newline") -else: - - def foo(): - pass - -with hmm_but_this_should_get_two_preceding_newlines(): - pass +NOT_YET_IMPLEMENTED_StmtWith ``` ## Black Output 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 ceeff81fdc..97bb06f0cd 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 @@ -108,19 +108,24 @@ def __await__(): return (yield) ```diff --- Black +++ Ruff -@@ -4,97 +4,67 @@ +@@ -1,148 +1,41 @@ + #!/usr/bin/env python3 +-import asyncio +-import sys ++NOT_YET_IMPLEMENTED_StmtImport ++NOT_YET_IMPLEMENTED_StmtImport - from third_party import X, Y, Z +-from third_party import X, Y, Z ++NOT_YET_IMPLEMENTED_StmtImportFrom -from library import some_connection, some_decorator -+from library import some_connection, \ -+ some_decorator -+f'trigger 3.6 mode' ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_ExprJoinedStr -f"trigger 3.6 mode" - - def func_no_args(): +-def func_no_args(): - a - b - c @@ -133,28 +138,18 @@ def __await__(): return (yield) - continue - exec("new-style exec", {}, {}) - return None -+ a; b; c -+ if True: raise RuntimeError -+ if False: ... -+ for i in range(10): -+ print(i) -+ continue -+ exec("new-style exec", {}, {}) -+ return None ++NOT_YET_IMPLEMENTED_StmtFunctionDef - async def coroutine(arg, exec=False): +-async def coroutine(arg, exec=False): - "Single-line docstring. Multiline is harder to reformat." - async with some_connection() as conn: - await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2) - await asyncio.sleep(1) -+ "Single-line docstring. Multiline is harder to reformat." -+ async with some_connection() as conn: -+ await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2) -+ await asyncio.sleep(1) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef - @asyncio.coroutine +-@asyncio.coroutine -@some_decorator(with_args=True, many_args=[1, 2, 3]) -def function_signature_stress_test( - number: int, @@ -165,20 +160,13 @@ def __await__(): return (yield) - **kwargs, -) -> str: - return text[number:-1] -+@some_decorator( -+with_args=True, -+many_args=[1,2,3] -+) -+def function_signature_stress_test(number:int,no_annotation=None,text:str="default",* ,debug:bool=False,**kwargs) -> str: -+ return text[number:-1] ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""): - offset = attr.ib(default=attr.Factory(lambda: _r.uniform(10000, 200000))) - assert task._cancel_stack[: len(old_stack)] == old_stack -+def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''): -+ offset = attr.ib(default=attr.Factory( lambda: _r.uniform(10000, 200000))) -+ assert task._cancel_stack[:len(old_stack)] == old_stack ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def spaces_types( @@ -193,16 +181,15 @@ def __await__(): return (yield) - i: str = r"", -): - ... -+def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ... ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def spaces2(result=_core.Value(None)): - assert fut is self._read_fut, (fut, self._read_fut) -+def spaces2(result= _core.Value(None)): -+ assert fut is self._read_fut, (fut, self._read_fut) ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def example(session): +-def example(session): - result = ( - session.query(models.Customer.id) - .filter( @@ -212,195 +199,126 @@ def __await__(): return (yield) - .order_by(models.Customer.id.asc()) - .all() - ) -+ result = session.query(models.Customer.id).filter( -+ models.Customer.account_id == account_id, -+ models.Customer.email == email_address, -+ ).order_by( -+ models.Customer.id.asc() -+ ).all() ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def long_lines(): - if True: - typedargslist.extend( +-def long_lines(): +- if True: +- typedargslist.extend( - gen_annotated_params( - ast_args.kwonlyargs, - ast_args.kw_defaults, - parameters, - implicit_default=True, - ) -+ gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True) - ) - typedargslist.extend( - gen_annotated_params( +- ) +- typedargslist.extend( +- gen_annotated_params( - ast_args.kwonlyargs, - ast_args.kw_defaults, - parameters, - implicit_default=True, -+ ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True, - # trailing standalone comment - ) - ) -@@ -117,23 +87,22 @@ - \n? - ) - $ +- # trailing standalone comment +- ) +- ) +- _type_comment_re = re.compile( +- r""" +- ^ +- [\t ]* +- \#[ ]type:[ ]* +- (?P +- [^#\t\n]+? +- ) +- (? to match +- # a trailing space which is why we need the silliness below +- (? +- (?:\#[^\n]*)? +- \n? +- ) +- $ - """, - re.MULTILINE | re.VERBOSE, -+ """, re.MULTILINE | re.VERBOSE - ) +- ) ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def trailing_comma(): - mapping = { +-def trailing_comma(): +- mapping = { - A: 0.25 * (10.0 / 12), - B: 0.1 * (10.0 / 12), - C: 0.1 * (10.0 / 12), - D: 0.1 * (10.0 / 12), - } -+ A: 0.25 * (10.0 / 12), -+ B: 0.1 * (10.0 / 12), -+ C: 0.1 * (10.0 / 12), -+ D: 0.1 * (10.0 / 12), -+} ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def f( +-def f( - a, - **kwargs, -+ a, -+ **kwargs, - ) -> A: - return ( - yield from A( -@@ -144,5 +113,4 @@ - ) +-) -> A: +- return ( +- yield from A( +- very_long_argument_name1=very_long_value_for_the_argument, +- very_long_argument_name2=very_long_value_for_the_argument, +- **kwargs, +- ) +- ) ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def __await__(): - return (yield) -+def __await__(): return (yield) ++NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Ruff Output ```py #!/usr/bin/env python3 -import asyncio -import sys +NOT_YET_IMPLEMENTED_StmtImport +NOT_YET_IMPLEMENTED_StmtImport -from third_party import X, Y, Z +NOT_YET_IMPLEMENTED_StmtImportFrom -from library import some_connection, \ - some_decorator -f'trigger 3.6 mode' +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_ExprJoinedStr -def func_no_args(): - a; b; c - if True: raise RuntimeError - if False: ... - for i in range(10): - print(i) - continue - exec("new-style exec", {}, {}) - return None +NOT_YET_IMPLEMENTED_StmtFunctionDef -async def coroutine(arg, exec=False): - "Single-line docstring. Multiline is harder to reformat." - async with some_connection() as conn: - await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2) - await asyncio.sleep(1) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -@asyncio.coroutine -@some_decorator( -with_args=True, -many_args=[1,2,3] -) -def function_signature_stress_test(number:int,no_annotation=None,text:str="default",* ,debug:bool=False,**kwargs) -> str: - return text[number:-1] +NOT_YET_IMPLEMENTED_StmtFunctionDef -def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''): - offset = attr.ib(default=attr.Factory( lambda: _r.uniform(10000, 200000))) - assert task._cancel_stack[:len(old_stack)] == old_stack +NOT_YET_IMPLEMENTED_StmtFunctionDef -def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ... +NOT_YET_IMPLEMENTED_StmtFunctionDef -def spaces2(result= _core.Value(None)): - assert fut is self._read_fut, (fut, self._read_fut) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def example(session): - result = session.query(models.Customer.id).filter( - models.Customer.account_id == account_id, - models.Customer.email == email_address, - ).order_by( - models.Customer.id.asc() - ).all() +NOT_YET_IMPLEMENTED_StmtFunctionDef -def long_lines(): - if True: - typedargslist.extend( - gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True) - ) - typedargslist.extend( - gen_annotated_params( - ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True, - # trailing standalone comment - ) - ) - _type_comment_re = re.compile( - r""" - ^ - [\t ]* - \#[ ]type:[ ]* - (?P - [^#\t\n]+? - ) - (? to match - # a trailing space which is why we need the silliness below - (? - (?:\#[^\n]*)? - \n? - ) - $ - """, re.MULTILINE | re.VERBOSE - ) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def trailing_comma(): - mapping = { - A: 0.25 * (10.0 / 12), - B: 0.1 * (10.0 / 12), - C: 0.1 * (10.0 / 12), - D: 0.1 * (10.0 / 12), -} +NOT_YET_IMPLEMENTED_StmtFunctionDef -def f( - a, - **kwargs, -) -> A: - return ( - yield from A( - very_long_argument_name1=very_long_value_for_the_argument, - very_long_argument_name2=very_long_value_for_the_argument, - **kwargs, - ) - ) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def __await__(): return (yield) +NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## 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 701a8007e7..6161c5951d 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 @@ -74,16 +74,15 @@ some_module.some_function( ```diff --- Black +++ Ruff -@@ -1,69 +1,28 @@ +@@ -1,114 +1,31 @@ -def f( - a, -): - d = { - "key": "value", - } -+def f(a,): -+ d = {'key': 'value',} - tup = (1,) +- tup = (1,) ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def f2( @@ -98,9 +97,7 @@ some_module.some_function( - 1, - 2, - ) -+def f2(a,b,): -+ d = {'key': 'value', 'key2': 'value2',} -+ tup = (1,2,) ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def f( @@ -114,13 +111,10 @@ some_module.some_function( - call2( - arg=[1, 2, 3], - ) -+def f(a:int=1,): -+ call(arg={'explode': 'this',}) -+ call2(arg=[1,2,3],) - x = { - "a": 1, - "b": 2, - }["a"] +- x = { +- "a": 1, +- "b": 2, +- }["a"] - if ( - a - == { @@ -134,8 +128,8 @@ some_module.some_function( - "h": 8, - }["a"] - ): -+ if a == {"a": 1,"b": 2,"c": 3,"d": 4,"e": 5,"f": 6,"g": 7,"h": 8,}["a"]: - pass +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> ( @@ -150,48 +144,51 @@ some_module.some_function( - } - } - } -+def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set[ -+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -+]: -+ json = {"k": {"k2": {"k3": [1,]}}} ++NOT_YET_IMPLEMENTED_StmtFunctionDef # The type annotation shouldn't get a trailing comma since that would change its type. -@@ -74,24 +33,21 @@ - pass + # Relevant bug report: https://github.com/psf/black/issues/2381. +-def some_function_with_a_really_long_name() -> ( +- returning_a_deeply_nested_import_of_a_type_i_suppose +-): +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef -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: -+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 - - - def func() -> ( -- also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black( -- this_shouldn_t_get_a_trailing_comma_too -- ) -+ also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(this_shouldn_t_get_a_trailing_comma_too) - ): - pass +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def func() -> ( - also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black( -+def func() -> ((also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black( - this_shouldn_t_get_a_trailing_comma_too +- this_shouldn_t_get_a_trailing_comma_too - ) -+ )) - ): - pass +-): +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef -@@ -103,12 +59,5 @@ + +-def func() -> ( +- also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black( +- this_shouldn_t_get_a_trailing_comma_too +- ) +-): +- pass ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + + # Make sure inner one-element tuple won't explode +-some_module.some_function( +- argument1, (one_element_tuple,), argument4, argument5, argument6 +-) ++NOT_YET_IMPLEMENTED_ExprCall # Inner trailing comma causes outer to explode - some_module.some_function( +-some_module.some_function( - argument1, - ( - one, @@ -200,76 +197,44 @@ some_module.some_function( - argument4, - argument5, - argument6, -+ argument1, (one, two,), argument4, argument5, argument6 - ) +-) ++NOT_YET_IMPLEMENTED_ExprCall ``` ## Ruff Output ```py -def f(a,): - d = {'key': 'value',} - tup = (1,) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def f2(a,b,): - d = {'key': 'value', 'key2': 'value2',} - tup = (1,2,) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def f(a:int=1,): - call(arg={'explode': 'this',}) - call2(arg=[1,2,3],) - x = { - "a": 1, - "b": 2, - }["a"] - if a == {"a": 1,"b": 2,"c": 3,"d": 4,"e": 5,"f": 6,"g": 7,"h": 8,}["a"]: - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set[ - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -]: - json = {"k": {"k2": {"k3": [1,]}}} +NOT_YET_IMPLEMENTED_StmtFunctionDef # The type annotation shouldn't get a trailing comma since that would change its type. # Relevant bug report: https://github.com/psf/black/issues/2381. -def some_function_with_a_really_long_name() -> ( - returning_a_deeply_nested_import_of_a_type_i_suppose -): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -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_StmtFunctionDef -def func() -> ( - also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(this_shouldn_t_get_a_trailing_comma_too) -): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def func() -> ((also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black( - this_shouldn_t_get_a_trailing_comma_too - )) -): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef # Make sure inner one-element tuple won't explode -some_module.some_function( - argument1, (one_element_tuple,), argument4, argument5, argument6 -) +NOT_YET_IMPLEMENTED_ExprCall # Inner trailing comma causes outer to explode -some_module.some_function( - argument1, (one, two,), argument4, argument5, argument6 -) +NOT_YET_IMPLEMENTED_ExprCall ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__import_spacing_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__import_spacing_py.snap index 13eab2b6d7..5a7d0cf00b 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__import_spacing_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__import_spacing_py.snap @@ -62,22 +62,44 @@ __all__ = ( ```diff --- Black +++ Ruff -@@ -2,8 +2,10 @@ +@@ -1,64 +1,31 @@ +-"""The asyncio package, tracking PEP 3156.""" ++NOT_YET_IMPLEMENTED_ExprConstant # flake8: noqa -from logging import WARNING - from logging import ( -+ WARNING -+) -+from logging import ( - ERROR, - ) - import sys -@@ -22,33 +24,16 @@ - from ..streams import * +-from logging import ( +- ERROR, +-) +-import sys ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImport - from some_library import ( + # This relies on each of the submodules having an __all__ variable. +-from .base_events import * +-from .coroutines import * +-from .events import * # comment here ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImportFrom # comment here + +-from .futures import * +-from .locks import * # comment here +-from .protocols import * ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImportFrom # comment here ++NOT_YET_IMPLEMENTED_StmtImportFrom + +-from ..runners import * # comment here +-from ..queues import * +-from ..streams import * ++NOT_YET_IMPLEMENTED_StmtImportFrom # comment here ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImportFrom + +-from some_library import ( - Just, - Enough, - Libraries, @@ -92,82 +114,76 @@ __all__ = ( - No, - Longer, - Use, -+ Just, Enough, Libraries, To, Fit, In, This, Nice, Split, Which, We, No, Longer, Use - ) +-) -from name_of_a_company.extremely_long_project_name.component.ttypes import ( - CuteLittleServiceHandlerFactoryyy, -) -+from name_of_a_company.extremely_long_project_name.component.ttypes import CuteLittleServiceHandlerFactoryyy - from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import * +-from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import * ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImportFrom - from .a.b.c.subprocess import * +-from .a.b.c.subprocess import * -from . import tasks -from . import A, B, C -from . import ( - SomeVeryLongNameAndAllOfItsAdditionalLetters1, - SomeVeryLongNameAndAllOfItsAdditionalLetters2, -) -+from . import (tasks) -+from . import (A, B, C) -+from . import SomeVeryLongNameAndAllOfItsAdditionalLetters1, \ -+ SomeVeryLongNameAndAllOfItsAdditionalLetters2 ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImportFrom ++NOT_YET_IMPLEMENTED_StmtImportFrom - __all__ = ( - base_events.__all__ +-__all__ = ( +- base_events.__all__ +- + coroutines.__all__ +- + events.__all__ +- + futures.__all__ +- + locks.__all__ +- + protocols.__all__ +- + runners.__all__ +- + queues.__all__ +- + streams.__all__ +- + tasks.__all__ +-) ++NOT_YET_IMPLEMENTED_StmtAssign ``` ## Ruff Output ```py -"""The asyncio package, tracking PEP 3156.""" +NOT_YET_IMPLEMENTED_ExprConstant # flake8: noqa -from logging import ( - WARNING -) -from logging import ( - ERROR, -) -import sys +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImport # This relies on each of the submodules having an __all__ variable. -from .base_events import * -from .coroutines import * -from .events import * # comment here +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom # comment here -from .futures import * -from .locks import * # comment here -from .protocols import * +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom # comment here +NOT_YET_IMPLEMENTED_StmtImportFrom -from ..runners import * # comment here -from ..queues import * -from ..streams import * +NOT_YET_IMPLEMENTED_StmtImportFrom # comment here +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom -from some_library import ( - Just, Enough, Libraries, To, Fit, In, This, Nice, Split, Which, We, No, Longer, Use -) -from name_of_a_company.extremely_long_project_name.component.ttypes import CuteLittleServiceHandlerFactoryyy -from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import * +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom -from .a.b.c.subprocess import * -from . import (tasks) -from . import (A, B, C) -from . import SomeVeryLongNameAndAllOfItsAdditionalLetters1, \ - SomeVeryLongNameAndAllOfItsAdditionalLetters2 +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom -__all__ = ( - base_events.__all__ - + coroutines.__all__ - + events.__all__ - + futures.__all__ - + locks.__all__ - + protocols.__all__ - + runners.__all__ - + queues.__all__ - + streams.__all__ - + tasks.__all__ -) +NOT_YET_IMPLEMENTED_StmtAssign ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__one_element_subscript_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__one_element_subscript_py.snap index 8b1a22c94f..8fc82df191 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__one_element_subscript_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__one_element_subscript_py.snap @@ -25,8 +25,13 @@ list_of_types = [tuple[int,],] ```diff --- Black +++ Ruff -@@ -4,19 +4,9 @@ - b = tuple[int,] +@@ -1,22 +1,12 @@ + # We should not treat the trailing comma + # in a single-element subscript. +-a: tuple[int,] +-b = tuple[int,] ++NOT_YET_IMPLEMENTED_StmtAnnAssign ++NOT_YET_IMPLEMENTED_StmtAssign # The magic comma still applies to multi-element subscripts. -c: tuple[ @@ -37,8 +42,8 @@ list_of_types = [tuple[int,],] - int, - int, -] -+c: tuple[int, int,] -+d = tuple[int, int,] ++NOT_YET_IMPLEMENTED_StmtAnnAssign ++NOT_YET_IMPLEMENTED_StmtAssign # Magic commas still work as expected for non-subscripts. -small_list = [ @@ -47,8 +52,8 @@ list_of_types = [tuple[int,],] -list_of_types = [ - tuple[int,], -] -+small_list = [1,] -+list_of_types = [tuple[int,],] ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ``` ## Ruff Output @@ -56,16 +61,16 @@ list_of_types = [tuple[int,],] ```py # We should not treat the trailing comma # in a single-element subscript. -a: tuple[int,] -b = tuple[int,] +NOT_YET_IMPLEMENTED_StmtAnnAssign +NOT_YET_IMPLEMENTED_StmtAssign # The magic comma still applies to multi-element subscripts. -c: tuple[int, int,] -d = tuple[int, int,] +NOT_YET_IMPLEMENTED_StmtAnnAssign +NOT_YET_IMPLEMENTED_StmtAssign # Magic commas still work as expected for non-subscripts. -small_list = [1,] -list_of_types = [tuple[int,],] +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign ``` ## Black Output 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 cc31431bdb..4fdf08fcb6 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,87 +76,166 @@ return np.divide( ```diff --- Black +++ Ruff -@@ -1,10 +1,10 @@ - def function(**kwargs): - t = a**2 + b**3 +@@ -1,63 +1,51 @@ +-def function(**kwargs): +- t = a**2 + b**3 - return t**2 -+ return t ** 2 ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def function_replace_spaces(**kwargs): +-def function_replace_spaces(**kwargs): - t = a**2 + b**3 + c**4 -+ t = a **2 + b** 3 + c ** 4 ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def function_dont_replace_spaces(): +-def function_dont_replace_spaces(): +- {**a, **b, **c} ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-a = 5**~4 +-b = 5 ** f() +-c = -(5**2) +-d = 5 ** f["hi"] +-e = lazy(lambda **kwargs: 5) +-f = f() ** 5 +-g = a.b**c.d +-h = 5 ** funcs.f() +-i = funcs.f() ** 5 +-j = super().name ** 5 +-k = [(2**idx, value) for idx, value in pairs] +-l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001) +-m = [([2**63], [1, 2**63])] +-n = count <= 10**5 +-o = settings(max_examples=10**6) +-p = {(k, k**2): v**2 for k, v in pairs} +-q = [10**i for i in range(6)] +-r = x**y ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign + +-a = 5.0**~4.0 +-b = 5.0 ** f() +-c = -(5.0**2.0) +-d = 5.0 ** f["hi"] +-e = lazy(lambda **kwargs: 5) +-f = f() ** 5.0 +-g = a.b**c.d +-h = 5.0 ** funcs.f() +-i = funcs.f() ** 5.0 +-j = super().name ** 5.0 +-k = [(2.0**idx, value) for idx, value in pairs] +-l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001) +-m = [([2.0**63.0], [1.0, 2**63.0])] +-n = count <= 10**5.0 +-o = settings(max_examples=10**6.0) +-p = {(k, k**2): v**2.0 for k, v in pairs} +-q = [10.5**i for i in range(6)] ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign + + + # WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873) +-if hasattr(view, "sum_of_weights"): +- return np.divide( # type: ignore[no-any-return] +- view.variance, # type: ignore[union-attr] +- view.sum_of_weights, # type: ignore[union-attr] +- out=np.full(view.sum_of_weights.shape, np.nan), # type: ignore[union-attr] +- where=view.sum_of_weights**2 > view.sum_of_weights_squared, # type: ignore[union-attr] +- ) ++NOT_YET_IMPLEMENTED_StmtIf + +-return np.divide( +- where=view.sum_of_weights_of_weight_long**2 > view.sum_of_weights_squared, # type: ignore +-) ++NOT_YET_IMPLEMENTED_StmtReturn ``` ## Ruff Output ```py -def function(**kwargs): - t = a**2 + b**3 - return t ** 2 +NOT_YET_IMPLEMENTED_StmtFunctionDef -def function_replace_spaces(**kwargs): - t = a **2 + b** 3 + c ** 4 +NOT_YET_IMPLEMENTED_StmtFunctionDef -def function_dont_replace_spaces(): - {**a, **b, **c} +NOT_YET_IMPLEMENTED_StmtFunctionDef -a = 5**~4 -b = 5 ** f() -c = -(5**2) -d = 5 ** f["hi"] -e = lazy(lambda **kwargs: 5) -f = f() ** 5 -g = a.b**c.d -h = 5 ** funcs.f() -i = funcs.f() ** 5 -j = super().name ** 5 -k = [(2**idx, value) for idx, value in pairs] -l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001) -m = [([2**63], [1, 2**63])] -n = count <= 10**5 -o = settings(max_examples=10**6) -p = {(k, k**2): v**2 for k, v in pairs} -q = [10**i for i in range(6)] -r = x**y +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign -a = 5.0**~4.0 -b = 5.0 ** f() -c = -(5.0**2.0) -d = 5.0 ** f["hi"] -e = lazy(lambda **kwargs: 5) -f = f() ** 5.0 -g = a.b**c.d -h = 5.0 ** funcs.f() -i = funcs.f() ** 5.0 -j = super().name ** 5.0 -k = [(2.0**idx, value) for idx, value in pairs] -l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001) -m = [([2.0**63.0], [1.0, 2**63.0])] -n = count <= 10**5.0 -o = settings(max_examples=10**6.0) -p = {(k, k**2): v**2.0 for k, v in pairs} -q = [10.5**i for i in range(6)] +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign # WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873) -if hasattr(view, "sum_of_weights"): - return np.divide( # type: ignore[no-any-return] - view.variance, # type: ignore[union-attr] - view.sum_of_weights, # type: ignore[union-attr] - out=np.full(view.sum_of_weights.shape, np.nan), # type: ignore[union-attr] - where=view.sum_of_weights**2 > view.sum_of_weights_squared, # type: ignore[union-attr] - ) +NOT_YET_IMPLEMENTED_StmtIf -return np.divide( - where=view.sum_of_weights_of_weight_long**2 > view.sum_of_weights_squared, # type: ignore -) +NOT_YET_IMPLEMENTED_StmtReturn ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__prefer_rhs_split_reformatted_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__prefer_rhs_split_reformatted_py.snap index 9f60197f9f..28e6705329 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__prefer_rhs_split_reformatted_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__prefer_rhs_split_reformatted_py.snap @@ -25,7 +25,7 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx ```diff --- Black +++ Ruff -@@ -2,20 +2,11 @@ +@@ -2,20 +2,8 @@ # Left hand side fits in a single line but will still be exploded by the # magic trailing comma. @@ -37,17 +37,17 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx - ), - third_value, -) = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv( -+first_value, (m1, m2,), third_value = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv( - arg1, - arg2, - ) +- arg1, +- arg2, +-) ++NOT_YET_IMPLEMENTED_StmtAssign # Make when when the left side of assignment plus the opening paren "... = (" is # exactly line length limit + 1, it won't be split like that. -xxxxxxxxx_yyy_zzzzzzzz[ - xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1) -] = 1 -+xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1)] = 1 ++NOT_YET_IMPLEMENTED_StmtAssign ``` ## Ruff Output @@ -57,14 +57,11 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx # Left hand side fits in a single line but will still be exploded by the # magic trailing comma. -first_value, (m1, m2,), third_value = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv( - arg1, - arg2, -) +NOT_YET_IMPLEMENTED_StmtAssign # Make when when the left side of assignment plus the opening paren "... = (" is # exactly line length limit + 1, it won't be split like that. -xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1)] = 1 +NOT_YET_IMPLEMENTED_StmtAssign ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_await_parens_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_await_parens_py.snap index 42f7589dcd..2d1804fc95 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_await_parens_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_await_parens_py.snap @@ -94,51 +94,51 @@ async def main(): ```diff --- Black +++ Ruff -@@ -8,59 +8,64 @@ +@@ -1,93 +1,60 @@ +-import asyncio ++NOT_YET_IMPLEMENTED_StmtImport + + + # Control example +-async def main(): +- await asyncio.sleep(1) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef + # Remove brackets for short coroutine/task - async def main(): +-async def main(): - await asyncio.sleep(1) -+ await (asyncio.sleep(1)) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef - async def main(): +-async def main(): - await asyncio.sleep(1) -+ await ( -+ asyncio.sleep(1) -+ ) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef - async def main(): +-async def main(): - await asyncio.sleep(1) -+ await (asyncio.sleep(1) -+ ) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Check comments - async def main(): +-async def main(): - await asyncio.sleep(1) # Hello -+ await ( # Hello -+ asyncio.sleep(1) -+ ) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef - async def main(): +-async def main(): - await asyncio.sleep(1) # Hello -+ await ( -+ asyncio.sleep(1) # Hello -+ ) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef - async def main(): +-async def main(): - await asyncio.sleep(1) # Hello -+ await ( -+ asyncio.sleep(1) -+ ) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Long lines - async def main(): +-async def main(): - await asyncio.gather( - asyncio.sleep(1), - asyncio.sleep(1), @@ -148,11 +148,11 @@ async def main(): - asyncio.sleep(1), - asyncio.sleep(1), - ) -+ await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1)) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Same as above but with magic trailing comma in function - async def main(): +-async def main(): - await asyncio.gather( - asyncio.sleep(1), - asyncio.sleep(1), @@ -162,145 +162,115 @@ async def main(): - asyncio.sleep(1), - asyncio.sleep(1), - ) -+ await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1),) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Cr@zY Br@ck3Tz - async def main(): +-async def main(): - await black(1) -+ await ( -+ ((((((((((((( -+ ((( ((( -+ ((( ((( -+ ((( ((( -+ ((( ((( -+ ((black(1))) -+ ))) ))) -+ ))) ))) -+ ))) ))) -+ ))) ))) -+ ))))))))))))) -+ ) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Keep brackets around non power operations and nested awaits -@@ -82,11 +87,11 @@ +-async def main(): +- await (set_of_tasks | other_set) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef - async def main(): +-async def main(): - await (await asyncio.sleep(1)) -+ await (await (asyncio.sleep(1))) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef - async def main(): + # It's awaits all the way down... +-async def main(): +- await (await x) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef + + +-async def main(): +- await (yield x) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef + + +-async def main(): +- await (await asyncio.sleep(1)) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef + + +-async def main(): - await (await (await (await (await asyncio.sleep(1))))) -+ await (await (await (await (await (asyncio.sleep(1)))))) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef - async def main(): +-async def main(): +- await (yield) ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef ``` ## Ruff Output ```py -import asyncio +NOT_YET_IMPLEMENTED_StmtImport # Control example -async def main(): - await asyncio.sleep(1) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Remove brackets for short coroutine/task -async def main(): - await (asyncio.sleep(1)) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -async def main(): - await ( - asyncio.sleep(1) - ) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -async def main(): - await (asyncio.sleep(1) - ) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Check comments -async def main(): - await ( # Hello - asyncio.sleep(1) - ) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -async def main(): - await ( - asyncio.sleep(1) # Hello - ) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -async def main(): - await ( - asyncio.sleep(1) - ) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Long lines -async def main(): - await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1)) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Same as above but with magic trailing comma in function -async def main(): - await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1),) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Cr@zY Br@ck3Tz -async def main(): - await ( - ((((((((((((( - ((( ((( - ((( ((( - ((( ((( - ((( ((( - ((black(1))) - ))) ))) - ))) ))) - ))) ))) - ))) ))) - ))))))))))))) - ) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # Keep brackets around non power operations and nested awaits -async def main(): - await (set_of_tasks | other_set) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -async def main(): - await (await asyncio.sleep(1)) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # It's awaits all the way down... -async def main(): - await (await x) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -async def main(): - await (yield x) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -async def main(): - await (await (asyncio.sleep(1))) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -async def main(): - await (await (await (await (await (asyncio.sleep(1)))))) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -async def main(): - await (yield) +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_except_parens_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_except_parens_py.snap index 7f435c1e2f..21fdd1942d 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_except_parens_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_except_parens_py.snap @@ -48,85 +48,69 @@ except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.ov ```diff --- Black +++ Ruff -@@ -1,42 +1,27 @@ +@@ -1,42 +1,9 @@ # These brackets are redundant, therefore remove. - try: - a.something +-try: +- a.something -except AttributeError as err: -+except (AttributeError) as err: - raise err +- raise err - -# This is tuple of exceptions. -# Although this could be replaced with just the exception, -# we do not remove brackets to preserve AST. - try: - a.something - except (AttributeError,) as err: - raise err +-try: +- a.something +-except (AttributeError,) as err: +- raise err - -# This is a tuple of exceptions. Do not remove brackets. - try: - a.something - except (AttributeError, ValueError) as err: - raise err +-try: +- a.something +-except (AttributeError, ValueError) as err: +- raise err - -# Test long variants. - try: - a.something +-try: +- a.something -except ( - some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error -) as err: -+except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err: - raise err +- raise err ++NOT_YET_IMPLEMENTED_StmtTry ++NOT_YET_IMPLEMENTED_StmtTry ++NOT_YET_IMPLEMENTED_StmtTry ++NOT_YET_IMPLEMENTED_StmtTry - try: - a.something +-try: +- a.something -except ( - some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, -) as err: -+except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,) as err: - raise err +- raise err ++NOT_YET_IMPLEMENTED_StmtTry - try: - a.something +-try: +- a.something -except ( - some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, - some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, -) as err: -+except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err: - raise err +- raise err ++NOT_YET_IMPLEMENTED_StmtTry ``` ## Ruff Output ```py # These brackets are redundant, therefore remove. -try: - a.something -except (AttributeError) as err: - raise err -try: - a.something -except (AttributeError,) as err: - raise err -try: - a.something -except (AttributeError, ValueError) as err: - raise err -try: - a.something -except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err: - raise err +NOT_YET_IMPLEMENTED_StmtTry +NOT_YET_IMPLEMENTED_StmtTry +NOT_YET_IMPLEMENTED_StmtTry +NOT_YET_IMPLEMENTED_StmtTry -try: - a.something -except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,) as err: - raise err +NOT_YET_IMPLEMENTED_StmtTry -try: - a.something -except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err: - raise err +NOT_YET_IMPLEMENTED_StmtTry ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_for_brackets_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_for_brackets_py.snap index 7f0c038d1f..dbdfdc6508 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_for_brackets_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_for_brackets_py.snap @@ -32,23 +32,25 @@ for (((((k, v))))) in d.items(): ```diff --- Black +++ Ruff -@@ -1,5 +1,5 @@ +@@ -1,27 +1,13 @@ # Only remove tuple brackets after `for` -for k, v in d.items(): -+for (k, v) in d.items(): - print(k, v) +- print(k, v) ++NOT_YET_IMPLEMENTED_StmtFor # Don't touch tuple brackets after `in` -@@ -8,20 +8,12 @@ - module._verify_python3_env = lambda: None +-for module in (core, _unicodefun): +- if hasattr(module, "_verify_python3_env"): +- module._verify_python3_env = lambda: None ++NOT_YET_IMPLEMENTED_StmtFor # Brackets remain for long for loop lines -for ( - why_would_anyone_choose_to_name_a_loop_variable_with_a_name_this_long, - i_dont_know_but_we_should_still_check_the_behaviour_if_they_do, -) in d.items(): -+for (why_would_anyone_choose_to_name_a_loop_variable_with_a_name_this_long, i_dont_know_but_we_should_still_check_the_behaviour_if_they_do) in d.items(): - print(k, v) +- print(k, v) ++NOT_YET_IMPLEMENTED_StmtFor -for ( - k, @@ -56,37 +58,31 @@ for (((((k, v))))) in d.items(): -) in ( - dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items() -): -+for (k, v) in dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items(): - print(k, v) +- print(k, v) ++NOT_YET_IMPLEMENTED_StmtFor # Test deeply nested brackets -for k, v in d.items(): -+for (((((k, v))))) in d.items(): - print(k, v) +- print(k, v) ++NOT_YET_IMPLEMENTED_StmtFor ``` ## Ruff Output ```py # Only remove tuple brackets after `for` -for (k, v) in d.items(): - print(k, v) +NOT_YET_IMPLEMENTED_StmtFor # Don't touch tuple brackets after `in` -for module in (core, _unicodefun): - if hasattr(module, "_verify_python3_env"): - module._verify_python3_env = lambda: None +NOT_YET_IMPLEMENTED_StmtFor # Brackets remain for long for loop lines -for (why_would_anyone_choose_to_name_a_loop_variable_with_a_name_this_long, i_dont_know_but_we_should_still_check_the_behaviour_if_they_do) in d.items(): - print(k, v) +NOT_YET_IMPLEMENTED_StmtFor -for (k, v) in dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items(): - print(k, v) +NOT_YET_IMPLEMENTED_StmtFor # Test deeply nested brackets -for (((((k, v))))) in d.items(): - print(k, v) +NOT_YET_IMPLEMENTED_StmtFor ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_newline_after_code_block_open_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_newline_after_code_block_open_py.snap index 7e1a6486b2..65e0869219 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_newline_after_code_block_open_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_newline_after_code_block_open_py.snap @@ -121,200 +121,168 @@ with open("/path/to/file.txt", mode="r") as read_file: ```diff --- Black +++ Ruff -@@ -2,20 +2,26 @@ +@@ -1,78 +1,56 @@ +-import random ++NOT_YET_IMPLEMENTED_StmtImport - def foo1(): -+ - print("The newline above me should be deleted!") +-def foo1(): +- print("The newline above me should be deleted!") ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def foo2(): -+ -+ -+ - print("All the newlines above me should be deleted!") +-def foo2(): +- print("All the newlines above me should be deleted!") ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def foo3(): -+ - print("No newline above me!") +-def foo3(): +- print("No newline above me!") ++NOT_YET_IMPLEMENTED_StmtFunctionDef - print("There is a newline above me, and that's OK!") +- print("There is a newline above me, and that's OK!") + ++NOT_YET_IMPLEMENTED_StmtFunctionDef + +-def foo4(): +- # There is a comment here + +- print("The newline above me should not be deleted!") ++NOT_YET_IMPLEMENTED_StmtClassDef - def foo4(): -+ - # There is a comment here - - print("The newline above me should not be deleted!") -@@ -23,27 +29,39 @@ - - class Foo: - def bar(self): -+ - print("The newline above me should be deleted!") +-class Foo: +- def bar(self): +- print("The newline above me should be deleted!") ++NOT_YET_IMPLEMENTED_StmtFor - for i in range(5): -+ - print(f"{i}) The line above me should be removed!") +-for i in range(5): +- print(f"{i}) The line above me should be removed!") ++NOT_YET_IMPLEMENTED_StmtFor - for i in range(5): -+ -+ -+ - print(f"{i}) The lines above me should be removed!") +-for i in range(5): +- print(f"{i}) The lines above me should be removed!") ++NOT_YET_IMPLEMENTED_StmtFor - for i in range(5): -+ - for j in range(7): -+ - print(f"{i}) The lines above me should be removed!") +-for i in range(5): +- for j in range(7): +- print(f"{i}) The lines above me should be removed!") ++NOT_YET_IMPLEMENTED_StmtIf - if random.randint(0, 3) == 0: -+ - print("The new line above me is about to be removed!") +-if random.randint(0, 3) == 0: +- print("The new line above me is about to be removed!") +- +- +-if random.randint(0, 3) == 0: +- print("The new lines above me is about to be removed!") ++NOT_YET_IMPLEMENTED_StmtIf - if random.randint(0, 3) == 0: -+ -+ -+ -+ - print("The new lines above me is about to be removed!") +-if random.randint(0, 3) == 0: +- if random.uniform(0, 1) > 0.5: +- print("Two lines above me are about to be removed!") ++NOT_YET_IMPLEMENTED_StmtIf -@@ -66,13 +84,19 @@ +-while True: +- print("The newline above me should be deleted!") ++while NOT_YET_IMPLEMENTED_ExprConstant: ++ NOT_YET_IMPLEMENTED_ExprCall - with open("/path/to/file.txt", mode="w") as file: -+ - file.write("The new line above me is about to be removed!") +-while True: +- print("The newlines above me should be deleted!") ++while NOT_YET_IMPLEMENTED_ExprConstant: ++ NOT_YET_IMPLEMENTED_ExprCall - with open("/path/to/file.txt", mode="w") as file: -+ -+ -+ - file.write("The new lines above me is about to be removed!") +-while True: +- while False: +- print("The newlines above me should be deleted!") ++while NOT_YET_IMPLEMENTED_ExprConstant: ++ while NOT_YET_IMPLEMENTED_ExprConstant: ++ NOT_YET_IMPLEMENTED_ExprCall - with open("/path/to/file.txt", mode="r") as read_file: -+ - with open("/path/to/output_file.txt", mode="w") as write_file: -+ - write_file.writelines(read_file.readlines()) +-with open("/path/to/file.txt", mode="w") as file: +- file.write("The new line above me is about to be removed!") ++NOT_YET_IMPLEMENTED_StmtWith + + +-with open("/path/to/file.txt", mode="w") as file: +- file.write("The new lines above me is about to be removed!") ++NOT_YET_IMPLEMENTED_StmtWith + + +-with open("/path/to/file.txt", mode="r") as read_file: +- with open("/path/to/output_file.txt", mode="w") as write_file: +- write_file.writelines(read_file.readlines()) ++NOT_YET_IMPLEMENTED_StmtWith ``` ## Ruff Output ```py -import random +NOT_YET_IMPLEMENTED_StmtImport -def foo1(): - - print("The newline above me should be deleted!") +NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo2(): +NOT_YET_IMPLEMENTED_StmtFunctionDef - - print("All the newlines above me should be deleted!") +NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo3(): - - print("No newline above me!") - - print("There is a newline above me, and that's OK!") +NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo4(): - - # There is a comment here - - print("The newline above me should not be deleted!") +NOT_YET_IMPLEMENTED_StmtClassDef -class Foo: - def bar(self): - - print("The newline above me should be deleted!") +NOT_YET_IMPLEMENTED_StmtFor -for i in range(5): - - print(f"{i}) The line above me should be removed!") +NOT_YET_IMPLEMENTED_StmtFor -for i in range(5): +NOT_YET_IMPLEMENTED_StmtFor - - print(f"{i}) The lines above me should be removed!") +NOT_YET_IMPLEMENTED_StmtIf -for i in range(5): - - for j in range(7): - - print(f"{i}) The lines above me should be removed!") +NOT_YET_IMPLEMENTED_StmtIf -if random.randint(0, 3) == 0: - - print("The new line above me is about to be removed!") +NOT_YET_IMPLEMENTED_StmtIf -if random.randint(0, 3) == 0: +while NOT_YET_IMPLEMENTED_ExprConstant: + NOT_YET_IMPLEMENTED_ExprCall +while NOT_YET_IMPLEMENTED_ExprConstant: + NOT_YET_IMPLEMENTED_ExprCall - print("The new lines above me is about to be removed!") +while NOT_YET_IMPLEMENTED_ExprConstant: + while NOT_YET_IMPLEMENTED_ExprConstant: + NOT_YET_IMPLEMENTED_ExprCall -if random.randint(0, 3) == 0: - if random.uniform(0, 1) > 0.5: - print("Two lines above me are about to be removed!") +NOT_YET_IMPLEMENTED_StmtWith -while True: - print("The newline above me should be deleted!") +NOT_YET_IMPLEMENTED_StmtWith -while True: - print("The newlines above me should be deleted!") - - -while True: - while False: - print("The newlines above me should be deleted!") - - -with open("/path/to/file.txt", mode="w") as file: - - file.write("The new line above me is about to be removed!") - - -with open("/path/to/file.txt", mode="w") as file: - - - - file.write("The new lines above me is about to be removed!") - - -with open("/path/to/file.txt", mode="r") as read_file: - - with open("/path/to/output_file.txt", mode="w") as write_file: - - write_file.writelines(read_file.readlines()) +NOT_YET_IMPLEMENTED_StmtWith ``` ## Black Output 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 7b2de231ae..e0a4c09c34 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,71 +68,75 @@ def example8(): ```diff --- Black +++ Ruff -@@ -1,5 +1,5 @@ +@@ -1,85 +1,37 @@ -x = 1 -x = 1.2 -+x = (1) -+x = (1.2) ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign - data = ( - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -@@ -11,75 +11,47 @@ - try: - if report_host: - data = ( +-data = ( +- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +-).encode() ++NOT_YET_IMPLEMENTED_StmtAssign + + +-async def show_status(): +- while True: +- try: +- if report_host: +- data = ( - f"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - ).encode() -+ f"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -+ ).encode() - except Exception as e: - pass +- except Exception as e: +- pass ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef - def example(): +-def example(): - return "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -+ return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")) ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def example1(): +-def example1(): - return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111 -+ return ((1111111111111111111111111111111111111111111111111111111111111111111111111111111111111)) ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def example1point5(): +-def example1point5(): - return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111 -+ return ((((((1111111111111111111111111111111111111111111111111111111111111111111111111111111111111)))))) ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def example2(): +-def example2(): - return ( - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - ) -+ return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")) ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def example3(): +-def example3(): - return ( - 1111111111111111111111111111111111111111111111111111111111111111111111111111111 - ) -+ return ((1111111111111111111111111111111111111111111111111111111111111111111111111111111)) ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def example4(): +-def example4(): - return True -+ return ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((True)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def example5(): +-def example5(): - return () -+ return ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def example6(): +-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]} -+ 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_StmtFunctionDef - def example7(): +-def example7(): - return { - a: a - for a in [ @@ -158,74 +162,54 @@ def example8(): - 20000000000000000000, - ] - } -+ return ((((((((({a:a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20000000000000000000]}))))))))) ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def example8(): +-def example8(): - return None -+ return (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((None))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) ++NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Ruff Output ```py -x = (1) -x = (1.2) +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign -data = ( - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -).encode() +NOT_YET_IMPLEMENTED_StmtAssign -async def show_status(): - while True: - try: - if report_host: - data = ( - f"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - ).encode() - except Exception as e: - pass +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef -def example(): - return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def example1(): - return ((1111111111111111111111111111111111111111111111111111111111111111111111111111111111111)) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def example1point5(): - return ((((((1111111111111111111111111111111111111111111111111111111111111111111111111111111111111)))))) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def example2(): - return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def example3(): - return ((1111111111111111111111111111111111111111111111111111111111111111111111111111111)) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def example4(): - return ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((True)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def example5(): - return ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) +NOT_YET_IMPLEMENTED_StmtFunctionDef -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_StmtFunctionDef -def example7(): - return ((((((((({a:a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20000000000000000000]}))))))))) +NOT_YET_IMPLEMENTED_StmtFunctionDef -def example8(): - return (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((None))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) +NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## 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 d09d9dfaa7..b5fb72b427 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,78 +101,67 @@ def foo() -> tuple[int, int, int,]: ```diff --- Black +++ Ruff -@@ -1,33 +1,41 @@ +@@ -1,120 +1,65 @@ # Control - def double(a: int) -> int: +-def double(a: int) -> int: - return 2 * a -+ return 2*a ++NOT_YET_IMPLEMENTED_StmtFunctionDef # Remove the brackets -def double(a: int) -> int: - return 2 * a -+def double(a: int) -> (int): -+ return 2*a ++NOT_YET_IMPLEMENTED_StmtFunctionDef # Some newline variations -def double(a: int) -> int: - return 2 * a -+def double(a: int) -> ( -+ int): -+ return 2*a ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def double(a: int) -> int: - return 2 * a -+def double(a: int) -> (int -+): -+ return 2*a ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def double(a: int) -> int: - return 2 * a -+def double(a: int) -> ( -+ int -+): -+ return 2*a ++NOT_YET_IMPLEMENTED_StmtFunctionDef # Don't lose the comments -def double(a: int) -> int: # Hello - return 2 * a -+def double(a: int) -> ( # Hello -+ int -+): -+ return 2*a ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def double(a: int) -> int: # Hello - return 2 * a -+def double(a: int) -> ( -+ int # Hello -+): -+ return 2*a ++NOT_YET_IMPLEMENTED_StmtFunctionDef # Really long annotations -@@ -37,84 +45,62 @@ - return 2 +-def foo() -> ( +- intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds +-): +- return 2 ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo() -> ( - intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds -): -+def foo() -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: - return 2 +- return 2 ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo() -> ( - intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds - | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds -): -+def foo() -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: - return 2 +- return 2 ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo( @@ -180,8 +169,8 @@ def foo() -> tuple[int, int, int,]: - b: int, - c: int, -) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: -+def foo(a: int, b: int, c: int,) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: - return 2 +- return 2 ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo( @@ -192,8 +181,8 @@ def foo() -> tuple[int, int, int,]: - intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds - | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds -): -+def foo(a: int, b: int, c: int,) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: - return 2 +- return 2 ++NOT_YET_IMPLEMENTED_StmtFunctionDef # Split args but no need to split return @@ -202,45 +191,33 @@ def foo() -> tuple[int, int, int,]: - b: int, - c: int, -) -> int: -+def foo(a: int, b: int, c: int,) -> int: - return 2 +- return 2 ++NOT_YET_IMPLEMENTED_StmtFunctionDef # Deeply nested brackets # with *interesting* spacing -def double(a: int) -> int: - return 2 * a -+def double(a: int) -> (((((int))))): -+ return 2*a ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def double(a: int) -> int: - return 2 * a -+def double(a: int) -> ( -+ ( ( -+ ((int) -+ ) -+ ) -+ ) -+ ): -+ return 2*a ++NOT_YET_IMPLEMENTED_StmtFunctionDef - def foo() -> ( -+ ( ( - intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds +-def foo() -> ( +- intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds -): -+) -+)): - return 2 +- return 2 ++NOT_YET_IMPLEMENTED_StmtFunctionDef # Return type with commas -def foo() -> tuple[int, int, int]: -+def foo() -> ( -+ tuple[int, int, int] -+): - return 2 +- return 2 ++NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo() -> ( @@ -250,8 +227,8 @@ def foo() -> tuple[int, int, int,]: - loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, - ] -): -+def foo() -> tuple[loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong]: - return 2 +- return 2 ++NOT_YET_IMPLEMENTED_StmtFunctionDef # Magic trailing comma example @@ -262,119 +239,78 @@ def foo() -> tuple[int, int, int,]: - int, - ] -): -+def foo() -> tuple[int, int, int,]: - return 2 +- return 2 ++NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Ruff Output ```py # Control -def double(a: int) -> int: - return 2*a +NOT_YET_IMPLEMENTED_StmtFunctionDef # Remove the brackets -def double(a: int) -> (int): - return 2*a +NOT_YET_IMPLEMENTED_StmtFunctionDef # Some newline variations -def double(a: int) -> ( - int): - return 2*a +NOT_YET_IMPLEMENTED_StmtFunctionDef -def double(a: int) -> (int -): - return 2*a +NOT_YET_IMPLEMENTED_StmtFunctionDef -def double(a: int) -> ( - int -): - return 2*a +NOT_YET_IMPLEMENTED_StmtFunctionDef # Don't lose the comments -def double(a: int) -> ( # Hello - int -): - return 2*a +NOT_YET_IMPLEMENTED_StmtFunctionDef -def double(a: int) -> ( - int # Hello -): - return 2*a +NOT_YET_IMPLEMENTED_StmtFunctionDef # Really long annotations -def foo() -> ( - intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds -): - return 2 +NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo() -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: - return 2 +NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo() -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: - return 2 +NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo(a: int, b: int, c: int,) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: - return 2 +NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo(a: int, b: int, c: int,) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds: - return 2 +NOT_YET_IMPLEMENTED_StmtFunctionDef # Split args but no need to split return -def foo(a: int, b: int, c: int,) -> int: - return 2 +NOT_YET_IMPLEMENTED_StmtFunctionDef # Deeply nested brackets # with *interesting* spacing -def double(a: int) -> (((((int))))): - return 2*a +NOT_YET_IMPLEMENTED_StmtFunctionDef -def double(a: int) -> ( - ( ( - ((int) - ) - ) - ) - ): - return 2*a +NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo() -> ( - ( ( - intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds -) -)): - return 2 +NOT_YET_IMPLEMENTED_StmtFunctionDef # Return type with commas -def foo() -> ( - tuple[int, int, int] -): - return 2 +NOT_YET_IMPLEMENTED_StmtFunctionDef -def foo() -> tuple[loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong]: - return 2 +NOT_YET_IMPLEMENTED_StmtFunctionDef # Magic trailing comma example -def foo() -> tuple[int, int, int,]: - return 2 +NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__skip_magic_trailing_comma_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__skip_magic_trailing_comma_py.snap index 4b710c3dde..8e328ab389 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__skip_magic_trailing_comma_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__skip_magic_trailing_comma_py.snap @@ -60,114 +60,75 @@ func( ```diff --- Black +++ Ruff -@@ -3,23 +3,45 @@ - b = tuple[int,] +@@ -1,25 +1,25 @@ + # We should not remove the trailing comma in a single-element subscript. +-a: tuple[int,] +-b = tuple[int,] ++NOT_YET_IMPLEMENTED_StmtAnnAssign ++NOT_YET_IMPLEMENTED_StmtAssign # But commas in multiple element subscripts should be removed. -c: tuple[int, int] -d = tuple[int, int] -+c: tuple[int, int,] -+d = tuple[int, int,] ++NOT_YET_IMPLEMENTED_StmtAnnAssign ++NOT_YET_IMPLEMENTED_StmtAssign # Remove commas for non-subscripts. -small_list = [1] -list_of_types = [tuple[int,]] -small_set = {1} -set_of_types = {tuple[int,]} -+small_list = [1,] -+list_of_types = [tuple[int,],] -+small_set = {1,} -+set_of_types = {tuple[int,],} ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign # Except single element tuples - small_tuple = (1,) +-small_tuple = (1,) ++NOT_YET_IMPLEMENTED_StmtAssign # Trailing commas in multiple chained non-nested parens. -zero(one).two(three).four(five) -+zero( -+ one, -+).two( -+ three, -+).four( -+ five, -+) ++NOT_YET_IMPLEMENTED_ExprCall -func1(arg1).func2(arg2).func3(arg3).func4(arg4).func5(arg5) -+func1(arg1).func2(arg2,).func3(arg3).func4(arg4,).func5(arg5) ++NOT_YET_IMPLEMENTED_ExprCall -(a, b, c, d) = func1(arg1) and func2(arg2) -+( -+ a, -+ b, -+ c, -+ d, -+) = func1( -+ arg1 -+) and func2(arg2) ++NOT_YET_IMPLEMENTED_StmtAssign -func(argument1, (one, two), argument4, argument5, argument6) -+func( -+ argument1, -+ ( -+ one, -+ two, -+ ), -+ argument4, -+ argument5, -+ argument6, -+) ++NOT_YET_IMPLEMENTED_ExprCall ``` ## Ruff Output ```py # We should not remove the trailing comma in a single-element subscript. -a: tuple[int,] -b = tuple[int,] +NOT_YET_IMPLEMENTED_StmtAnnAssign +NOT_YET_IMPLEMENTED_StmtAssign # But commas in multiple element subscripts should be removed. -c: tuple[int, int,] -d = tuple[int, int,] +NOT_YET_IMPLEMENTED_StmtAnnAssign +NOT_YET_IMPLEMENTED_StmtAssign # Remove commas for non-subscripts. -small_list = [1,] -list_of_types = [tuple[int,],] -small_set = {1,} -set_of_types = {tuple[int,],} +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign # Except single element tuples -small_tuple = (1,) +NOT_YET_IMPLEMENTED_StmtAssign # Trailing commas in multiple chained non-nested parens. -zero( - one, -).two( - three, -).four( - five, -) +NOT_YET_IMPLEMENTED_ExprCall -func1(arg1).func2(arg2,).func3(arg3).func4(arg4,).func5(arg5) +NOT_YET_IMPLEMENTED_ExprCall -( - a, - b, - c, - d, -) = func1( - arg1 -) and func2(arg2) +NOT_YET_IMPLEMENTED_StmtAssign -func( - argument1, - ( - one, - two, - ), - argument4, - argument5, - argument6, -) +NOT_YET_IMPLEMENTED_ExprCall ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__slices_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__slices_py.snap index fcfa1edd86..c862c14f5e 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__slices_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__slices_py.snap @@ -76,127 +76,137 @@ x[ ```diff --- Black +++ Ruff -@@ -31,14 +31,17 @@ - ham[lower + offset : upper + offset] +@@ -1,59 +1,37 @@ +-slice[a.b : c.d] +-slice[d :: d + 1] +-slice[d + 1 :: d] +-slice[d::d] +-slice[0] +-slice[-1] +-slice[:-1] +-slice[::-1] +-slice[:c, c - 1] +-slice[c, c + 1, d::] +-slice[ham[c::d] :: 1] +-slice[ham[cheese**2 : -1] : 1 : 1, ham[1:2]] +-slice[:-1:] +-slice[lambda: None : lambda: None] +-slice[lambda x, y, *args, really=2, **kwargs: None :, None::] +-slice[1 or 2 : True and False] +-slice[not so_simple : 1 < val <= 10] +-slice[(1 for i in range(42)) : x] +-slice[:: [i for i in range(42)]] ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript - slice[::, ::] + +-async def f(): +- slice[await x : [i async for i in arange(42)] : 42] ++NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef + + + # These are from PEP-8: +-ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:] +-ham[lower:upper], ham[lower:upper:], ham[lower::step] ++NOT_YET_IMPLEMENTED_ExprTuple ++NOT_YET_IMPLEMENTED_ExprTuple + # ham[lower+offset : upper+offset] +-ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)] +-ham[lower + offset : upper + offset] ++NOT_YET_IMPLEMENTED_ExprTuple ++NOT_YET_IMPLEMENTED_ExprSubscript + +-slice[::, ::] -slice[ -+( -+ slice[ - # A - : - # B - : - # C - ] +- # A +- : +- # B +- : +- # C +-] -slice[ -+) -+( -+ slice[ - # A - 1: - # B -@@ -46,8 +49,10 @@ - # C - 3 - ] -+) +- # A +- 1: +- # B +- 2: +- # C +- 3 +-] ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript -slice[ -+( -+ slice[ - # A - 1 - + 2 : -@@ -56,4 +61,11 @@ - # C - 4 - ] +- # A +- 1 +- + 2 : +- # B +- 3 : +- # C +- 4 +-] -x[1:2:3] # A # B # C -+) -+( -+ x[ -+ 1: # A -+ 2: # B -+ 3 # C -+] -+) ++NOT_YET_IMPLEMENTED_ExprSubscript ++NOT_YET_IMPLEMENTED_ExprSubscript ``` ## Ruff Output ```py -slice[a.b : c.d] -slice[d :: d + 1] -slice[d + 1 :: d] -slice[d::d] -slice[0] -slice[-1] -slice[:-1] -slice[::-1] -slice[:c, c - 1] -slice[c, c + 1, d::] -slice[ham[c::d] :: 1] -slice[ham[cheese**2 : -1] : 1 : 1, ham[1:2]] -slice[:-1:] -slice[lambda: None : lambda: None] -slice[lambda x, y, *args, really=2, **kwargs: None :, None::] -slice[1 or 2 : True and False] -slice[not so_simple : 1 < val <= 10] -slice[(1 for i in range(42)) : x] -slice[:: [i for i in range(42)]] +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript -async def f(): - slice[await x : [i async for i in arange(42)] : 42] +NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef # These are from PEP-8: -ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:] -ham[lower:upper], ham[lower:upper:], ham[lower::step] +NOT_YET_IMPLEMENTED_ExprTuple +NOT_YET_IMPLEMENTED_ExprTuple # ham[lower+offset : upper+offset] -ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)] -ham[lower + offset : upper + offset] +NOT_YET_IMPLEMENTED_ExprTuple +NOT_YET_IMPLEMENTED_ExprSubscript -slice[::, ::] -( - slice[ - # A - : - # B - : - # C -] -) -( - slice[ - # A - 1: - # B - 2: - # C - 3 -] -) +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript -( - slice[ - # A - 1 - + 2 : - # B - 3 : - # C - 4 -] -) -( - x[ - 1: # A - 2: # B - 3 # C -] -) +NOT_YET_IMPLEMENTED_ExprSubscript +NOT_YET_IMPLEMENTED_ExprSubscript ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__string_prefixes_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__string_prefixes_py.snap index 07e263b90e..b0a462f74d 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__string_prefixes_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__string_prefixes_py.snap @@ -33,25 +33,36 @@ def docstring_multiline(): ```diff --- Black +++ Ruff -@@ -1,13 +1,13 @@ +@@ -1,20 +1,16 @@ #!/usr/bin/env python3 - name = "Łukasz" +-name = "Łukasz" -(f"hello {name}", f"hello {name}") -(b"", b"") -("", "") -+(f"hello {name}", F"hello {name}") -+(b"", B"") -+(u"", U"") - (r"", R"") +-(r"", R"") ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_ExprTuple ++NOT_YET_IMPLEMENTED_ExprTuple ++NOT_YET_IMPLEMENTED_ExprTuple ++NOT_YET_IMPLEMENTED_ExprTuple -(rf"", rf"", Rf"", Rf"", rf"", rf"", Rf"", Rf"") -(rb"", rb"", Rb"", Rb"", rb"", rb"", Rb"", Rb"") -+(rf"", fr"", Rf"", fR"", rF"", Fr"", RF"", FR"") -+(rb"", br"", Rb"", bR"", rB"", Br"", RB"", BR"") ++NOT_YET_IMPLEMENTED_ExprTuple ++NOT_YET_IMPLEMENTED_ExprTuple - def docstring_singleline(): +-def docstring_singleline(): +- R"""2020 was one hell of a year. The good news is that we were able to""" ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + +-def docstring_multiline(): +- R""" +- clear out all of the issues opened in that time :p +- """ ++NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## Ruff Output @@ -59,24 +70,20 @@ def docstring_multiline(): ```py #!/usr/bin/env python3 -name = "Łukasz" -(f"hello {name}", F"hello {name}") -(b"", B"") -(u"", U"") -(r"", R"") +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_ExprTuple +NOT_YET_IMPLEMENTED_ExprTuple +NOT_YET_IMPLEMENTED_ExprTuple +NOT_YET_IMPLEMENTED_ExprTuple -(rf"", fr"", Rf"", fR"", rF"", Fr"", RF"", FR"") -(rb"", br"", Rb"", bR"", rB"", Br"", RB"", BR"") +NOT_YET_IMPLEMENTED_ExprTuple +NOT_YET_IMPLEMENTED_ExprTuple -def docstring_singleline(): - R"""2020 was one hell of a year. The good news is that we were able to""" +NOT_YET_IMPLEMENTED_StmtFunctionDef -def docstring_multiline(): - R""" - clear out all of the issues opened in that time :p - """ +NOT_YET_IMPLEMENTED_StmtFunctionDef ``` ## 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 42d322316d..68d336c517 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 @@ -42,16 +42,18 @@ assert ( ```diff --- Black +++ Ruff -@@ -2,18 +2,13 @@ +@@ -1,58 +1,20 @@ + importA ( - () - << 0 +- () +- << 0 - ** 101234234242352525425252352352525234890264906820496920680926538059059209922523523525 -+ **101234234242352525425252352352525234890264906820496920680926538059059209922523523525 ++ NOT_YET_IMPLEMENTED_ExprTuple ++ << NOT_YET_IMPLEMENTED_ExprConstant**NOT_YET_IMPLEMENTED_ExprConstant ) # - assert sort_by_dependency( - { +-assert sort_by_dependency( +- { - "1": {"2", "3"}, - "2": {"2a", "2b"}, - "3": {"3a", "3b"}, @@ -59,23 +61,27 @@ assert ( - "2b": set(), - "3a": set(), - "3b": set(), -+ "1": {"2", "3"}, "2": {"2a", "2b"}, "3": {"3a", "3b"}, -+ "2a": set(), "2b": set(), "3a": set(), "3b": set() - } - ) == ["2a", "2b", "2", "3a", "3b", "3", "1"] +- } +-) == ["2a", "2b", "2", "3a", "3b", "3", "1"] ++NOT_YET_IMPLEMENTED_StmtAssert -@@ -25,34 +20,18 @@ - class A: - def foo(self): - for _ in range(10): + importA +-0 +-0 ^ 0 # ++NOT_YET_IMPLEMENTED_ExprConstant ++NOT_YET_IMPLEMENTED_ExprConstant ^ NOT_YET_IMPLEMENTED_ExprConstant # + + +-class A: +- def foo(self): +- for _ in range(10): - aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( -+ aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( # pylint: disable=no-member - xxxxxxxxxxxx +- xxxxxxxxxxxx - ) # pylint: disable=no-member -+ ) ++NOT_YET_IMPLEMENTED_StmtClassDef - def test(self, othr): +-def test(self, othr): - return 1 == 2 and ( - name, - description, @@ -95,19 +101,14 @@ assert ( - othr.meta_data, - othr.schedule, - ) -+ return (1 == 2 and -+ (name, description, self.default, self.selected, self.auto_generated, self.parameters, self.meta_data, self.schedule) == -+ (name, description, othr.default, othr.selected, othr.auto_generated, othr.parameters, othr.meta_data, othr.schedule)) ++NOT_YET_IMPLEMENTED_StmtFunctionDef -assert a_function( - very_long_arguments_that_surpass_the_limit, - which_is_eighty_eight_in_this_case_plus_a_bit_more, -) == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"} -+assert ( -+ a_function(very_long_arguments_that_surpass_the_limit, which_is_eighty_eight_in_this_case_plus_a_bit_more) -+ == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"} -+) ++NOT_YET_IMPLEMENTED_StmtAssert ``` ## Ruff Output @@ -115,41 +116,24 @@ assert ( ```py importA ( - () - << 0 - **101234234242352525425252352352525234890264906820496920680926538059059209922523523525 + NOT_YET_IMPLEMENTED_ExprTuple + << NOT_YET_IMPLEMENTED_ExprConstant**NOT_YET_IMPLEMENTED_ExprConstant ) # -assert sort_by_dependency( - { - "1": {"2", "3"}, "2": {"2a", "2b"}, "3": {"3a", "3b"}, - "2a": set(), "2b": set(), "3a": set(), "3b": set() - } -) == ["2a", "2b", "2", "3a", "3b", "3", "1"] +NOT_YET_IMPLEMENTED_StmtAssert importA -0 -0 ^ 0 # +NOT_YET_IMPLEMENTED_ExprConstant +NOT_YET_IMPLEMENTED_ExprConstant ^ NOT_YET_IMPLEMENTED_ExprConstant # -class A: - def foo(self): - for _ in range(10): - aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( # pylint: disable=no-member - xxxxxxxxxxxx - ) +NOT_YET_IMPLEMENTED_StmtClassDef -def test(self, othr): - return (1 == 2 and - (name, description, self.default, self.selected, self.auto_generated, self.parameters, self.meta_data, self.schedule) == - (name, description, othr.default, othr.selected, othr.auto_generated, othr.parameters, othr.meta_data, othr.schedule)) +NOT_YET_IMPLEMENTED_StmtFunctionDef -assert ( - a_function(very_long_arguments_that_surpass_the_limit, which_is_eighty_eight_in_this_case_plus_a_bit_more) - == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"} -) +NOT_YET_IMPLEMENTED_StmtAssert ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens1_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens1_py.snap index a6989d984a..dd2cf4c4ad 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens1_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens1_py.snap @@ -38,17 +38,16 @@ class A: ```diff --- Black +++ Ruff -@@ -1,18 +1,11 @@ +@@ -1,34 +1,9 @@ -if e1234123412341234.winerror not in ( - _winapi.ERROR_SEM_TIMEOUT, - _winapi.ERROR_PIPE_BUSY, -) or _check_timeout(t): -+if e1234123412341234.winerror not in (_winapi.ERROR_SEM_TIMEOUT, -+ _winapi.ERROR_PIPE_BUSY) or _check_timeout(t): - pass +- pass ++NOT_YET_IMPLEMENTED_StmtIf - if x: - if y: +-if x: +- if y: - new_id = ( - max( - Vegetable.objects.order_by("-id")[0].id, @@ -56,52 +55,42 @@ class A: - ) - + 1 - ) -+ new_id = max(Vegetable.objects.order_by('-id')[0].id, -+ Mineral.objects.order_by('-id')[0].id) + 1 ++NOT_YET_IMPLEMENTED_StmtIf - class X: -@@ -21,7 +14,7 @@ - "Your password must contain at least %(min_length)d character.", - "Your password must contain at least %(min_length)d characters.", - self.min_length, +-class X: +- def get_help_text(self): +- return ngettext( +- "Your password must contain at least %(min_length)d character.", +- "Your password must contain at least %(min_length)d characters.", +- self.min_length, - ) % {"min_length": self.min_length} -+ ) % {'min_length': self.min_length} ++NOT_YET_IMPLEMENTED_StmtClassDef - class A: +-class A: +- def b(self): +- if self.connection.mysql_is_mariadb and ( +- 10, +- 4, +- 3, +- ) < self.connection.mysql_version < (10, 5, 2): +- pass ++NOT_YET_IMPLEMENTED_StmtClassDef ``` ## Ruff Output ```py -if e1234123412341234.winerror not in (_winapi.ERROR_SEM_TIMEOUT, - _winapi.ERROR_PIPE_BUSY) or _check_timeout(t): - pass +NOT_YET_IMPLEMENTED_StmtIf -if x: - if y: - new_id = max(Vegetable.objects.order_by('-id')[0].id, - Mineral.objects.order_by('-id')[0].id) + 1 +NOT_YET_IMPLEMENTED_StmtIf -class X: - def get_help_text(self): - return ngettext( - "Your password must contain at least %(min_length)d character.", - "Your password must contain at least %(min_length)d characters.", - self.min_length, - ) % {'min_length': self.min_length} +NOT_YET_IMPLEMENTED_StmtClassDef -class A: - def b(self): - if self.connection.mysql_is_mariadb and ( - 10, - 4, - 3, - ) < self.connection.mysql_version < (10, 5, 2): - pass +NOT_YET_IMPLEMENTED_StmtClassDef ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens2_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens2_py.snap index 4b8ed29e06..6512172b1d 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens2_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens2_py.snap @@ -16,23 +16,20 @@ if (e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') or ```diff --- Black +++ Ruff -@@ -1,6 +1,3 @@ +@@ -1,6 +1 @@ -if e123456.get_tk_patchlevel() >= (8, 6, 0, "final") or ( - 8, - 5, - 8, -) <= get_tk_patchlevel() < (8, 6): -+if (e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') or -+ (8, 5, 8) <= get_tk_patchlevel() < (8, 6)): - pass +- pass ++NOT_YET_IMPLEMENTED_StmtIf ``` ## Ruff Output ```py -if (e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') or - (8, 5, 8) <= get_tk_patchlevel() < (8, 6)): - pass +NOT_YET_IMPLEMENTED_StmtIf ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens3_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens3_py.snap new file mode 100644 index 0000000000..cd0d0a2216 --- /dev/null +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens3_py.snap @@ -0,0 +1,55 @@ +--- +source: crates/ruff_python_formatter/src/lib.rs +expression: snapshot +input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens3.py +--- +## Input + +```py +if True: + if True: + if True: + return _( + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas " + + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.", + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe", + ) % {"reported_username": reported_username, "report_reason": report_reason} +``` + +## Black Differences + +```diff +--- Black ++++ Ruff +@@ -1,8 +1 @@ +-if True: +- if True: +- if True: +- return _( +- "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas " +- + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.", +- "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe", +- ) % {"reported_username": reported_username, "report_reason": report_reason} ++NOT_YET_IMPLEMENTED_StmtIf +``` + +## Ruff Output + +```py +NOT_YET_IMPLEMENTED_StmtIf +``` + +## Black Output + +```py +if True: + if True: + if True: + return _( + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas " + + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.", + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe", + ) % {"reported_username": reported_username, "report_reason": report_reason} +``` + + 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 80f18068cb..4e8beee766 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 @@ -46,7 +46,7 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx( ```diff --- Black +++ Ruff -@@ -1,28 +1,11 @@ +@@ -1,50 +1,20 @@ -zero( - one, -).two( @@ -54,17 +54,18 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx( -).four( - five, -) -+zero(one,).two(three,).four(five,) ++NOT_YET_IMPLEMENTED_ExprCall -func1(arg1).func2( - arg2, -).func3(arg3).func4( - arg4, -).func5(arg5) -+func1(arg1).func2(arg2,).func3(arg3).func4(arg4,).func5(arg5) ++NOT_YET_IMPLEMENTED_ExprCall # Inner one-element tuple shouldn't explode - func1(arg1).func2(arg1, (one_tuple,)).func3(arg3) +-func1(arg1).func2(arg1, (one_tuple,)).func3(arg3) ++NOT_YET_IMPLEMENTED_ExprCall -( - a, @@ -74,48 +75,60 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx( -) = func1( - arg1 -) and func2(arg2) -+(a, b, c, d,) = func1(arg1) and func2(arg2) ++NOT_YET_IMPLEMENTED_StmtAssign # Example from https://github.com/psf/black/issues/3229 +-def refresh_token(self, device_family, refresh_token, api_key): +- return self.orchestration.refresh_token( +- data={ +- "refreshToken": refresh_token, +- }, +- api_key=api_key, +- )["extensions"]["sdk"]["token"] ++NOT_YET_IMPLEMENTED_StmtFunctionDef + + + # Edge case where a bug in a working-in-progress version of + # https://github.com/psf/black/pull/3370 causes an infinite recursion. +-assert ( +- long_module.long_class.long_func().another_func() +- == long_module.long_class.long_func()["some_key"].another_func(arg1) +-) ++NOT_YET_IMPLEMENTED_StmtAssert + + # Regression test for https://github.com/psf/black/issues/3414. +-assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx( +- xxxxxxxxx +-).xxxxxxxxxxxxxxxxxx(), ( +- "xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +-) ++NOT_YET_IMPLEMENTED_StmtAssert ``` ## Ruff Output ```py -zero(one,).two(three,).four(five,) +NOT_YET_IMPLEMENTED_ExprCall -func1(arg1).func2(arg2,).func3(arg3).func4(arg4,).func5(arg5) +NOT_YET_IMPLEMENTED_ExprCall # Inner one-element tuple shouldn't explode -func1(arg1).func2(arg1, (one_tuple,)).func3(arg3) +NOT_YET_IMPLEMENTED_ExprCall -(a, b, c, d,) = func1(arg1) and func2(arg2) +NOT_YET_IMPLEMENTED_StmtAssign # Example from https://github.com/psf/black/issues/3229 -def refresh_token(self, device_family, refresh_token, api_key): - return self.orchestration.refresh_token( - data={ - "refreshToken": refresh_token, - }, - api_key=api_key, - )["extensions"]["sdk"]["token"] +NOT_YET_IMPLEMENTED_StmtFunctionDef # Edge case where a bug in a working-in-progress version of # https://github.com/psf/black/pull/3370 causes an infinite recursion. -assert ( - long_module.long_class.long_func().another_func() - == long_module.long_class.long_func()["some_key"].another_func(arg1) -) +NOT_YET_IMPLEMENTED_StmtAssert # Regression test for https://github.com/psf/black/issues/3414. -assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx( - xxxxxxxxx -).xxxxxxxxxxxxxxxxxx(), ( - "xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -) +NOT_YET_IMPLEMENTED_StmtAssert ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tricky_unicode_symbols_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tricky_unicode_symbols_py.snap new file mode 100644 index 0000000000..c288ae7783 --- /dev/null +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tricky_unicode_symbols_py.snap @@ -0,0 +1,73 @@ +--- +source: crates/ruff_python_formatter/src/lib.rs +expression: snapshot +input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tricky_unicode_symbols.py +--- +## Input + +```py +ä = 1 +µ = 2 +蟒 = 3 +x󠄀 = 4 +មុ = 1 +Q̇_per_meter = 4 + +A᧚ = 3 +A፩ = 8 +``` + +## Black Differences + +```diff +--- Black ++++ Ruff +@@ -1,9 +1,9 @@ +-ä = 1 +-µ = 2 +-蟒 = 3 +-x󠄀 = 4 +-មុ = 1 +-Q̇_per_meter = 4 ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign + +-A᧚ = 3 +-A፩ = 8 ++NOT_YET_IMPLEMENTED_StmtAssign ++NOT_YET_IMPLEMENTED_StmtAssign +``` + +## Ruff Output + +```py +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign + +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign +``` + +## Black Output + +```py +ä = 1 +µ = 2 +蟒 = 3 +x󠄀 = 4 +មុ = 1 +Q̇_per_meter = 4 + +A᧚ = 3 +A፩ = 8 +``` + + diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tupleassign_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tupleassign_py.snap index d4c4d3546f..6a0ef755cd 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tupleassign_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tupleassign_py.snap @@ -28,25 +28,26 @@ this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890") - sdfsdjfklsdfjlksdljkf, - sdsfsdfjskdflsfsdf, -) = (1, 2, 3) -+sdfjklsdfsjldkflkjsf, sdfjsdfjlksdljkfsdlkf, sdfsdjfklsdfjlksdljkf, sdsfsdfjskdflsfsdf = 1, 2, 3 ++NOT_YET_IMPLEMENTED_StmtAssign # This is as well. -(this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890") -+this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890") ++NOT_YET_IMPLEMENTED_StmtAssign - (a,) = call() +-(a,) = call() ++NOT_YET_IMPLEMENTED_StmtAssign ``` ## Ruff Output ```py # This is a standalone comment. -sdfjklsdfsjldkflkjsf, sdfjsdfjlksdljkfsdlkf, sdfsdjfklsdfjlksdljkf, sdsfsdfjskdflsfsdf = 1, 2, 3 +NOT_YET_IMPLEMENTED_StmtAssign # This is as well. -this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890") +NOT_YET_IMPLEMENTED_StmtAssign -(a,) = call() +NOT_YET_IMPLEMENTED_StmtAssign ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__binary_expression_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__binary_expression_py.snap index 530a88cc06..15d11d8aa0 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__binary_expression_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__binary_expression_py.snap @@ -68,40 +68,19 @@ not (aaaaaaaaaaaaaa + {a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb # Black breaks the right side first for the following expressions: -( - aaaaaaaaaaaaaa - + caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal(argument1, argument2, argument3) -) +aaaaaaaaaaaaaa + NOT_YET_IMPLEMENTED_ExprCall aaaaaaaaaaaaaa + [ bbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc, dddddddddddddddd, eeeeeee, ] -( - aaaaaaaaaaaaaa - + (bbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc, dddddddddddddddd, eeeeeee) -) -( - aaaaaaaaaaaaaa - + { key1:bbbbbbbbbbbbbbbbbbbbbb, key2: ccccccccccccccccccccc, key3: dddddddddddddddd, key4: eeeeeee } -) -( - aaaaaaaaaaaaaa - + { bbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc, dddddddddddddddd, eeeeeee } -) -( - aaaaaaaaaaaaaa - + [a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ] -) -( - aaaaaaaaaaaaaa - + (a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ) -) -( - aaaaaaaaaaaaaa - + {a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb} -) +aaaaaaaaaaaaaa + NOT_YET_IMPLEMENTED_ExprTuple +aaaaaaaaaaaaaa + NOT_YET_IMPLEMENTED_ExprDict +aaaaaaaaaaaaaa + NOT_YET_IMPLEMENTED_ExprSet +aaaaaaaaaaaaaa + NOT_YET_IMPLEMENTED_ExprListComp +aaaaaaaaaaaaaa + NOT_YET_IMPLEMENTED_ExprGeneratorExp +aaaaaaaaaaaaaa + NOT_YET_IMPLEMENTED_ExprSetComp # Wraps it in parentheses if it needs to break both left and right ( @@ -111,12 +90,8 @@ aaaaaaaaaaaaaa + [ # But only for expressions that have a statement parent. -( - not (aaaaaaaaaaaaaa + {a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb}) -) -[ - a + [bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] in c, -] +NOT_YET_IMPLEMENTED_ExprUnaryOp +[NOT_YET_IMPLEMENTED_ExprCompare] # leading comment diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__while_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__while_py.snap index 9ef6ca4e90..d9a6a35769 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__while_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__while_py.snap @@ -40,15 +40,15 @@ while ( ## Output ```py -while 34: # trailing test comment - pass # trailing last statement comment +while NOT_YET_IMPLEMENTED_ExprConstant: # trailing test comment + NOT_YET_IMPLEMENTED_StmtPass # trailing last statement comment # trailing while body comment # leading else comment else: # trailing else comment - pass + NOT_YET_IMPLEMENTED_StmtPass # trailing else body comment @@ -56,20 +56,19 @@ else: # trailing else comment while ( aVeryLongConditionThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn ): # trailing comment - pass + NOT_YET_IMPLEMENTED_StmtPass else: - ... + NOT_YET_IMPLEMENTED_ExprConstant -while some_condition(unformatted, args) and anotherCondition or aThirdCondition: # comment - print("Do something") +while NOT_YET_IMPLEMENTED_ExprBoolOp: # comment + NOT_YET_IMPLEMENTED_ExprCall while ( - some_condition(unformatted, args) # trailing some condition - and anotherCondition or aThirdCondition # trailing third condition + NOT_YET_IMPLEMENTED_ExprBoolOp # trailing third condition ): # comment - print("Do something") + NOT_YET_IMPLEMENTED_ExprCall ``` diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__trivia_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__trivia_py.snap index 226cb148c5..7364029b27 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__trivia_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__trivia_py.snap @@ -44,37 +44,35 @@ e = 50 # one empty line before ```py # Removes the line above -a = 10 # Keeps the line above +NOT_YET_IMPLEMENTED_StmtAssign # Keeps the line above # Separated by one line from `a` and `b` -b = 20 +NOT_YET_IMPLEMENTED_StmtAssign # Adds two lines after `b` -class Test: - def a(self): - pass +NOT_YET_IMPLEMENTED_StmtClassDef # two lines before, one line after -c = 30 +NOT_YET_IMPLEMENTED_StmtAssign -while a == 10: - ... +while NOT_YET_IMPLEMENTED_ExprCompare: + NOT_YET_IMPLEMENTED_ExprConstant # trailing comment with one line before # one line before this leading comment -d = 40 +NOT_YET_IMPLEMENTED_StmtAssign -while b == 20: - ... +while NOT_YET_IMPLEMENTED_ExprCompare: + NOT_YET_IMPLEMENTED_ExprConstant # no empty line before -e = 50 # one empty line before +NOT_YET_IMPLEMENTED_StmtAssign # one empty line before ``` diff --git a/crates/ruff_python_formatter/src/statement/stmt_ann_assign.rs b/crates/ruff_python_formatter/src/statement/stmt_ann_assign.rs index 721c219304..645808d940 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_ann_assign.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_ann_assign.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtAnnAssign; @@ -7,6 +7,6 @@ pub struct FormatStmtAnnAssign; impl FormatNodeRule for FormatStmtAnnAssign { fn fmt_fields(&self, item: &StmtAnnAssign, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_assert.rs b/crates/ruff_python_formatter/src/statement/stmt_assert.rs index 1cd34b93a5..1631051c4e 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_assert.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_assert.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtAssert; @@ -7,6 +7,6 @@ pub struct FormatStmtAssert; impl FormatNodeRule for FormatStmtAssert { fn fmt_fields(&self, item: &StmtAssert, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_assign.rs b/crates/ruff_python_formatter/src/statement/stmt_assign.rs index 3b7d95c8da..92fce60ad5 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_assign.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_assign.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtAssign; @@ -7,6 +7,6 @@ pub struct FormatStmtAssign; impl FormatNodeRule for FormatStmtAssign { fn fmt_fields(&self, item: &StmtAssign, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_async_for.rs b/crates/ruff_python_formatter/src/statement/stmt_async_for.rs index d69c0ecf26..2718289fb8 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_async_for.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_async_for.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtAsyncFor; @@ -7,6 +7,6 @@ pub struct FormatStmtAsyncFor; impl FormatNodeRule for FormatStmtAsyncFor { fn fmt_fields(&self, item: &StmtAsyncFor, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_async_function_def.rs b/crates/ruff_python_formatter/src/statement/stmt_async_function_def.rs index e3bd34df1b..c81a5f0eaa 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_async_function_def.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_async_function_def.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtAsyncFunctionDef; @@ -7,6 +7,6 @@ pub struct FormatStmtAsyncFunctionDef; impl FormatNodeRule for FormatStmtAsyncFunctionDef { fn fmt_fields(&self, item: &StmtAsyncFunctionDef, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_async_with.rs b/crates/ruff_python_formatter/src/statement/stmt_async_with.rs index 1ce677f4d9..0555642a10 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_async_with.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_async_with.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtAsyncWith; @@ -7,6 +7,6 @@ pub struct FormatStmtAsyncWith; impl FormatNodeRule for FormatStmtAsyncWith { fn fmt_fields(&self, item: &StmtAsyncWith, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_aug_assign.rs b/crates/ruff_python_formatter/src/statement/stmt_aug_assign.rs index 34f9a299c5..8db5a6a8d4 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_aug_assign.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_aug_assign.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtAugAssign; @@ -7,6 +7,6 @@ pub struct FormatStmtAugAssign; impl FormatNodeRule for FormatStmtAugAssign { fn fmt_fields(&self, item: &StmtAugAssign, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_break.rs b/crates/ruff_python_formatter/src/statement/stmt_break.rs index 8ad401b17a..f3e9af3ca2 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_break.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_break.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtBreak; @@ -7,6 +7,6 @@ pub struct FormatStmtBreak; impl FormatNodeRule for FormatStmtBreak { fn fmt_fields(&self, item: &StmtBreak, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_class_def.rs b/crates/ruff_python_formatter/src/statement/stmt_class_def.rs index 69f5a77c49..5c2f8db3ab 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_class_def.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_class_def.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtClassDef; @@ -7,6 +7,6 @@ pub struct FormatStmtClassDef; impl FormatNodeRule for FormatStmtClassDef { fn fmt_fields(&self, item: &StmtClassDef, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_continue.rs b/crates/ruff_python_formatter/src/statement/stmt_continue.rs index 461d4dc431..b216ba7c46 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_continue.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_continue.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtContinue; @@ -7,6 +7,6 @@ pub struct FormatStmtContinue; impl FormatNodeRule for FormatStmtContinue { fn fmt_fields(&self, item: &StmtContinue, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_delete.rs b/crates/ruff_python_formatter/src/statement/stmt_delete.rs index 1b446a16fa..0a75dcd016 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_delete.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_delete.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtDelete; @@ -7,6 +7,6 @@ pub struct FormatStmtDelete; impl FormatNodeRule for FormatStmtDelete { fn fmt_fields(&self, item: &StmtDelete, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_for.rs b/crates/ruff_python_formatter/src/statement/stmt_for.rs index 11c162ebf0..b943de7cc1 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_for.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_for.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtFor; @@ -7,6 +7,6 @@ pub struct FormatStmtFor; impl FormatNodeRule for FormatStmtFor { fn fmt_fields(&self, item: &StmtFor, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_function_def.rs b/crates/ruff_python_formatter/src/statement/stmt_function_def.rs index c8263f07c3..e39f24f2ac 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_function_def.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_function_def.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtFunctionDef; @@ -7,6 +7,6 @@ pub struct FormatStmtFunctionDef; impl FormatNodeRule for FormatStmtFunctionDef { fn fmt_fields(&self, item: &StmtFunctionDef, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_global.rs b/crates/ruff_python_formatter/src/statement/stmt_global.rs index a7b73a55fe..ae0da78e2e 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_global.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_global.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtGlobal; @@ -7,6 +7,6 @@ pub struct FormatStmtGlobal; impl FormatNodeRule for FormatStmtGlobal { fn fmt_fields(&self, item: &StmtGlobal, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_if.rs b/crates/ruff_python_formatter/src/statement/stmt_if.rs index 94a2715d33..bbef308f49 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_if.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_if.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtIf; @@ -7,6 +7,6 @@ pub struct FormatStmtIf; impl FormatNodeRule for FormatStmtIf { fn fmt_fields(&self, item: &StmtIf, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_import.rs b/crates/ruff_python_formatter/src/statement/stmt_import.rs index fa1f7bfdf7..2585dfade7 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_import.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_import.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtImport; @@ -7,6 +7,6 @@ pub struct FormatStmtImport; impl FormatNodeRule for FormatStmtImport { fn fmt_fields(&self, item: &StmtImport, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_import_from.rs b/crates/ruff_python_formatter/src/statement/stmt_import_from.rs index 4d1d7c2371..bdae4d56ba 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_import_from.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_import_from.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtImportFrom; @@ -7,6 +7,6 @@ pub struct FormatStmtImportFrom; impl FormatNodeRule for FormatStmtImportFrom { fn fmt_fields(&self, item: &StmtImportFrom, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_match.rs b/crates/ruff_python_formatter/src/statement/stmt_match.rs index aac63a7730..22d76a6676 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_match.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_match.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtMatch; @@ -7,6 +7,6 @@ pub struct FormatStmtMatch; impl FormatNodeRule for FormatStmtMatch { fn fmt_fields(&self, item: &StmtMatch, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_nonlocal.rs b/crates/ruff_python_formatter/src/statement/stmt_nonlocal.rs index feb4056513..459a60b057 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_nonlocal.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_nonlocal.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtNonlocal; @@ -7,6 +7,6 @@ pub struct FormatStmtNonlocal; impl FormatNodeRule for FormatStmtNonlocal { fn fmt_fields(&self, item: &StmtNonlocal, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_pass.rs b/crates/ruff_python_formatter/src/statement/stmt_pass.rs index fdffb521ce..f8a04e0163 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_pass.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_pass.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtPass; @@ -7,6 +7,6 @@ pub struct FormatStmtPass; impl FormatNodeRule for FormatStmtPass { fn fmt_fields(&self, item: &StmtPass, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_raise.rs b/crates/ruff_python_formatter/src/statement/stmt_raise.rs index d480275a44..47372372a5 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_raise.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_raise.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtRaise; @@ -7,6 +7,6 @@ pub struct FormatStmtRaise; impl FormatNodeRule for FormatStmtRaise { fn fmt_fields(&self, item: &StmtRaise, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_return.rs b/crates/ruff_python_formatter/src/statement/stmt_return.rs index 1da4170f9f..02da2a73d0 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_return.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_return.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtReturn; @@ -7,6 +7,6 @@ pub struct FormatStmtReturn; impl FormatNodeRule for FormatStmtReturn { fn fmt_fields(&self, item: &StmtReturn, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_try.rs b/crates/ruff_python_formatter/src/statement/stmt_try.rs index c2bceff327..35afc06669 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_try.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_try.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtTry; @@ -7,6 +7,6 @@ pub struct FormatStmtTry; impl FormatNodeRule for FormatStmtTry { fn fmt_fields(&self, item: &StmtTry, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_try_star.rs b/crates/ruff_python_formatter/src/statement/stmt_try_star.rs index 098966fb7f..aa4d45c444 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_try_star.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_try_star.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtTryStar; @@ -7,6 +7,6 @@ pub struct FormatStmtTryStar; impl FormatNodeRule for FormatStmtTryStar { fn fmt_fields(&self, item: &StmtTryStar, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/stmt_with.rs b/crates/ruff_python_formatter/src/statement/stmt_with.rs index ab19089eda..a68ee33113 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_with.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_with.rs @@ -1,4 +1,4 @@ -use crate::{verbatim_text, FormatNodeRule, PyFormatter}; +use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; use ruff_formatter::{write, Buffer, FormatResult}; use rustpython_parser::ast::StmtWith; @@ -7,6 +7,6 @@ pub struct FormatStmtWith; impl FormatNodeRule for FormatStmtWith { fn fmt_fields(&self, item: &StmtWith, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [verbatim_text(item.range)]) + write!(f, [not_yet_implemented(item)]) } } diff --git a/crates/ruff_python_formatter/src/statement/suite.rs b/crates/ruff_python_formatter/src/statement/suite.rs index 02f190a4c2..3d943ba647 100644 --- a/crates/ruff_python_formatter/src/statement/suite.rs +++ b/crates/ruff_python_formatter/src/statement/suite.rs @@ -234,31 +234,28 @@ def trailing_func(): assert_eq!( formatted, - r#"a = 10 + r#"NOT_YET_IMPLEMENTED_StmtAssign -three_leading_newlines = 80 +NOT_YET_IMPLEMENTED_StmtAssign -two_leading_newlines = 20 +NOT_YET_IMPLEMENTED_StmtAssign -one_leading_newline = 10 -no_leading_newline = 30 +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign -class InTheMiddle: - pass +NOT_YET_IMPLEMENTED_StmtClassDef -trailing_statement = 1 +NOT_YET_IMPLEMENTED_StmtAssign -def func(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def trailing_func(): - pass"# +NOT_YET_IMPLEMENTED_StmtFunctionDef"# ); } @@ -268,25 +265,22 @@ def trailing_func(): assert_eq!( formatted, - r#"a = 10 + r#"NOT_YET_IMPLEMENTED_StmtAssign -three_leading_newlines = 80 +NOT_YET_IMPLEMENTED_StmtAssign -two_leading_newlines = 20 +NOT_YET_IMPLEMENTED_StmtAssign -one_leading_newline = 10 -no_leading_newline = 30 +NOT_YET_IMPLEMENTED_StmtAssign +NOT_YET_IMPLEMENTED_StmtAssign -class InTheMiddle: - pass +NOT_YET_IMPLEMENTED_StmtClassDef -trailing_statement = 1 +NOT_YET_IMPLEMENTED_StmtAssign -def func(): - pass +NOT_YET_IMPLEMENTED_StmtFunctionDef -def trailing_func(): - pass"# +NOT_YET_IMPLEMENTED_StmtFunctionDef"# ); } }