From c1cc6f3be1af7af38f44b059dd3ba6308c321689 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 8 Jun 2023 13:42:44 +0200 Subject: [PATCH] Add basic Constant formatting (#4954) --- crates/ruff_python_formatter/src/builders.rs | 30 +- .../src/expression/expr_attribute.rs | 28 +- .../src/expression/expr_bool_op.rs | 3 +- .../src/expression/expr_call.rs | 7 +- .../src/expression/expr_compare.rs | 3 +- .../src/expression/expr_constant.rs | 34 +- .../src/expression/expr_dict.rs | 3 +- .../src/expression/expr_dict_comp.rs | 3 +- .../src/expression/expr_generator_exp.rs | 7 +- .../src/expression/expr_if_exp.rs | 3 +- .../src/expression/expr_lambda.rs | 4 +- .../src/expression/expr_list_comp.rs | 7 +- .../src/expression/expr_slice.rs | 3 +- .../src/expression/expr_subscript.rs | 3 +- .../src/expression/expr_tuple.rs | 4 +- crates/ruff_python_formatter/src/lib.rs | 40 +-- ...ttribute_access_on_number_literals_py.snap | 24 +- ...er__tests__black_test__collections_py.snap | 49 +-- ...tter__tests__black_test__comments2_py.snap | 117 +++---- ...tter__tests__black_test__comments5_py.snap | 19 +- ...tter__tests__black_test__comments6_py.snap | 4 +- ..._test__comments_non_breaking_space_py.snap | 15 +- ...atter__tests__black_test__comments_py.snap | 43 ++- ...er__tests__black_test__empty_lines_py.snap | 4 +- ...ter__tests__black_test__expression_py.snap | 320 +++++++++--------- ...tter__tests__black_test__fmtonoff2_py.snap | 12 +- ...tter__tests__black_test__fmtonoff3_py.snap | 13 +- ...atter__tests__black_test__fmtonoff_py.snap | 4 +- ...atter__tests__black_test__fmtskip2_py.snap | 42 ++- ...atter__tests__black_test__fmtskip3_py.snap | 18 +- ...atter__tests__black_test__fmtskip4_py.snap | 9 +- ...atter__tests__black_test__fmtskip7_py.snap | 17 +- ...matter__tests__black_test__fmtskip_py.snap | 9 +- ..._tests__black_test__import_spacing_py.snap | 4 +- ..._black_test__one_element_subscript_py.snap | 4 +- ...ests__black_test__power_op_spacing_py.snap | 56 +-- ...test__prefer_rhs_split_reformatted_py.snap | 4 +- ...move_newline_after_code_block_open_py.snap | 28 +- ...__tests__black_test__remove_parens_py.snap | 10 +- ...ck_test__skip_magic_trailing_comma_py.snap | 12 +- ...tests__black_test__string_prefixes_py.snap | 4 +- ...matter__tests__black_test__torture_py.snap | 27 +- ...black_test__tricky_unicode_symbols_py.snap | 73 ---- ..._ruff_test__statement__stmt_assign_py.snap | 6 +- ...tests__ruff_test__statement__while_py.snap | 4 +- ...ormatter__tests__ruff_test__trivia_py.snap | 14 +- .../src/statement/suite.rs | 24 +- 47 files changed, 548 insertions(+), 623 deletions(-) delete mode 100644 crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tricky_unicode_symbols_py.snap diff --git a/crates/ruff_python_formatter/src/builders.rs b/crates/ruff_python_formatter/src/builders.rs index afcaeaf59baed..847df4d3c5e13 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 = 0x42 + r#"a = 10 -three_leading_newlines = 0x42 +three_leading_newlines = 80 -two_leading_newlines = 0x42 +two_leading_newlines = 20 -one_leading_newline = 0x42 -no_leading_newline = 0x42"# +one_leading_newline = 10 +no_leading_newline = 30"# ); } @@ -211,14 +211,14 @@ no_leading_newline = 0x42"# assert_eq!( &printed, - r#"a = 0x42 + r#"a = 10 -three_leading_newlines = 0x42 +three_leading_newlines = 80 -two_leading_newlines = 0x42 +two_leading_newlines = 20 -one_leading_newline = 0x42 -no_leading_newline = 0x42"# +one_leading_newline = 10 +no_leading_newline = 30"# ); } @@ -229,11 +229,11 @@ no_leading_newline = 0x42"# assert_eq!( &printed, - r#"a = 0x42 -three_leading_newlines = 0x42 -two_leading_newlines = 0x42 -one_leading_newline = 0x42 -no_leading_newline = 0x42"# + r#"a = 10 +three_leading_newlines = 80 +two_leading_newlines = 20 +one_leading_newline = 10 +no_leading_newline = 30"# ); } } diff --git a/crates/ruff_python_formatter/src/expression/expr_attribute.rs b/crates/ruff_python_formatter/src/expression/expr_attribute.rs index 9e540cd1b323e..31ca2c9a32a6a 100644 --- a/crates/ruff_python_formatter/src/expression/expr_attribute.rs +++ b/crates/ruff_python_formatter/src/expression/expr_attribute.rs @@ -1,24 +1,38 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{not_yet_implemented_custom_text, AsFormat, FormatNodeRule, PyFormatter}; -use ruff_formatter::prelude::text; -use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::ExprAttribute; +use crate::prelude::*; +use crate::{not_yet_implemented_custom_text, FormatNodeRule}; +use ruff_formatter::write; +use rustpython_parser::ast::{Constant, Expr, ExprAttribute, ExprConstant}; #[derive(Default)] pub struct FormatExprAttribute; impl FormatNodeRule for FormatExprAttribute { fn fmt_fields(&self, item: &ExprAttribute, f: &mut PyFormatter) -> FormatResult<()> { - // We need to write the value - which is also a dummy - already because power op spacing - // depends on it + let ExprAttribute { + value, + range: _, + attr: _, + ctx: _, + } = item; + + let requires_space = matches!( + value.as_ref(), + Expr::Constant(ExprConstant { + value: Constant::Int(_) | Constant::Float(_), + .. + }) + ); + write!( f, [ item.value.format(), + requires_space.then_some(space()), text("."), - not_yet_implemented_custom_text(item, "NOT_IMPLEMENTED_attr") + not_yet_implemented_custom_text("NOT_IMPLEMENTED_attr") ] ) } 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 b031b528462ca..41ebc548965d0 100644 --- a/crates/ruff_python_formatter/src/expression/expr_bool_op.rs +++ b/crates/ruff_python_formatter/src/expression/expr_bool_op.rs @@ -9,11 +9,10 @@ use rustpython_parser::ast::ExprBoolOp; pub struct FormatExprBoolOp; impl FormatNodeRule for FormatExprBoolOp { - fn fmt_fields(&self, item: &ExprBoolOp, f: &mut PyFormatter) -> FormatResult<()> { + fn fmt_fields(&self, _item: &ExprBoolOp, f: &mut PyFormatter) -> FormatResult<()> { write!( f, [not_yet_implemented_custom_text( - item, "NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2" )] ) diff --git a/crates/ruff_python_formatter/src/expression/expr_call.rs b/crates/ruff_python_formatter/src/expression/expr_call.rs index efee31804e17d..4338619cc8e1e 100644 --- a/crates/ruff_python_formatter/src/expression/expr_call.rs +++ b/crates/ruff_python_formatter/src/expression/expr_call.rs @@ -9,13 +9,10 @@ use rustpython_parser::ast::ExprCall; pub struct FormatExprCall; impl FormatNodeRule for FormatExprCall { - fn fmt_fields(&self, item: &ExprCall, f: &mut PyFormatter) -> FormatResult<()> { + fn fmt_fields(&self, _item: &ExprCall, f: &mut PyFormatter) -> FormatResult<()> { write!( f, - [not_yet_implemented_custom_text( - item, - "NOT_IMPLEMENTED_call()" - )] + [not_yet_implemented_custom_text("NOT_IMPLEMENTED_call()")] ) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_compare.rs b/crates/ruff_python_formatter/src/expression/expr_compare.rs index a69a34f4b186e..428f3ed1ce231 100644 --- a/crates/ruff_python_formatter/src/expression/expr_compare.rs +++ b/crates/ruff_python_formatter/src/expression/expr_compare.rs @@ -10,11 +10,10 @@ use rustpython_parser::ast::ExprCompare; pub struct FormatExprCompare; impl FormatNodeRule for FormatExprCompare { - fn fmt_fields(&self, item: &ExprCompare, f: &mut PyFormatter) -> FormatResult<()> { + fn fmt_fields(&self, _item: &ExprCompare, f: &mut PyFormatter) -> FormatResult<()> { write!( f, [not_yet_implemented_custom_text( - item, "NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right" )] ) diff --git a/crates/ruff_python_formatter/src/expression/expr_constant.rs b/crates/ruff_python_formatter/src/expression/expr_constant.rs index dec14ba361481..1579ed5b5cf6b 100644 --- a/crates/ruff_python_formatter/src/expression/expr_constant.rs +++ b/crates/ruff_python_formatter/src/expression/expr_constant.rs @@ -1,16 +1,42 @@ use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; -use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter}; -use ruff_formatter::{write, Buffer, FormatResult}; -use rustpython_parser::ast::ExprConstant; +use crate::prelude::*; +use crate::{not_yet_implemented_custom_text, verbatim_text, FormatNodeRule}; +use ruff_formatter::write; +use rustpython_parser::ast::{Constant, ExprConstant}; #[derive(Default)] pub struct FormatExprConstant; impl FormatNodeRule for FormatExprConstant { fn fmt_fields(&self, item: &ExprConstant, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [not_yet_implemented_custom_text(item, "0x42")]) + let ExprConstant { + range: _, + value, + kind: _, + } = item; + + match value { + Constant::Ellipsis => text("...").fmt(f), + Constant::None => text("None").fmt(f), + Constant::Bool(value) => match value { + true => text("True").fmt(f), + false => text("False").fmt(f), + }, + Constant::Int(_) | Constant::Float(_) | Constant::Complex { .. } => { + write!(f, [verbatim_text(item)]) + } + Constant::Str(_) => { + not_yet_implemented_custom_text(r#""NOT_YET_IMPLEMENTED_STRING""#).fmt(f) + } + Constant::Bytes(_) => { + not_yet_implemented_custom_text(r#"b"NOT_YET_IMPLEMENTED_BYTE_STRING""#).fmt(f) + } + Constant::Tuple(_) => { + not_yet_implemented_custom_text("(NOT_YET_IMPLEMENTED_TUPLE,)").fmt(f) + } + } } } diff --git a/crates/ruff_python_formatter/src/expression/expr_dict.rs b/crates/ruff_python_formatter/src/expression/expr_dict.rs index fb84073dcfbd8..6f173b26ab7f9 100644 --- a/crates/ruff_python_formatter/src/expression/expr_dict.rs +++ b/crates/ruff_python_formatter/src/expression/expr_dict.rs @@ -9,11 +9,10 @@ use rustpython_parser::ast::ExprDict; pub struct FormatExprDict; impl FormatNodeRule for FormatExprDict { - fn fmt_fields(&self, item: &ExprDict, f: &mut PyFormatter) -> FormatResult<()> { + fn fmt_fields(&self, _item: &ExprDict, f: &mut PyFormatter) -> FormatResult<()> { write!( f, [not_yet_implemented_custom_text( - item, "{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}" )] ) 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 102c189288b25..6a3337f573e39 100644 --- a/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs @@ -9,11 +9,10 @@ use rustpython_parser::ast::ExprDictComp; pub struct FormatExprDictComp; impl FormatNodeRule for FormatExprDictComp { - fn fmt_fields(&self, item: &ExprDictComp, f: &mut PyFormatter) -> FormatResult<()> { + fn fmt_fields(&self, _item: &ExprDictComp, f: &mut PyFormatter) -> FormatResult<()> { write!( f, [not_yet_implemented_custom_text( - item, "{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}" )] ) 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 c3685aa71185a..2cf35598eabe7 100644 --- a/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs @@ -9,11 +9,8 @@ use rustpython_parser::ast::ExprGeneratorExp; pub struct FormatExprGeneratorExp; impl FormatNodeRule for FormatExprGeneratorExp { - fn fmt_fields(&self, item: &ExprGeneratorExp, f: &mut PyFormatter) -> FormatResult<()> { - write!( - f, - [not_yet_implemented_custom_text(item, "(i for i in [])")] - ) + fn fmt_fields(&self, _item: &ExprGeneratorExp, f: &mut PyFormatter) -> FormatResult<()> { + write!(f, [not_yet_implemented_custom_text("(i for i in [])")]) } } 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 a35278f6526fe..e60ebbf8f0a73 100644 --- a/crates/ruff_python_formatter/src/expression/expr_if_exp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_if_exp.rs @@ -9,11 +9,10 @@ use rustpython_parser::ast::ExprIfExp; pub struct FormatExprIfExp; impl FormatNodeRule for FormatExprIfExp { - fn fmt_fields(&self, item: &ExprIfExp, f: &mut PyFormatter) -> FormatResult<()> { + fn fmt_fields(&self, _item: &ExprIfExp, f: &mut PyFormatter) -> FormatResult<()> { write!( f, [not_yet_implemented_custom_text( - item, "NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false" )] ) diff --git a/crates/ruff_python_formatter/src/expression/expr_lambda.rs b/crates/ruff_python_formatter/src/expression/expr_lambda.rs index ee3ef2bcb0444..c1310de391f53 100644 --- a/crates/ruff_python_formatter/src/expression/expr_lambda.rs +++ b/crates/ruff_python_formatter/src/expression/expr_lambda.rs @@ -9,8 +9,8 @@ use rustpython_parser::ast::ExprLambda; pub struct FormatExprLambda; impl FormatNodeRule for FormatExprLambda { - fn fmt_fields(&self, item: &ExprLambda, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [not_yet_implemented_custom_text(item, "lambda x: True")]) + fn fmt_fields(&self, _item: &ExprLambda, f: &mut PyFormatter) -> FormatResult<()> { + write!(f, [not_yet_implemented_custom_text("lambda x: True")]) } } 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 1769e07f9af16..8fddfa5457849 100644 --- a/crates/ruff_python_formatter/src/expression/expr_list_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_list_comp.rs @@ -9,11 +9,8 @@ use rustpython_parser::ast::ExprListComp; pub struct FormatExprListComp; impl FormatNodeRule for FormatExprListComp { - fn fmt_fields(&self, item: &ExprListComp, f: &mut PyFormatter) -> FormatResult<()> { - write!( - f, - [not_yet_implemented_custom_text(item, "[i for i in []]")] - ) + fn fmt_fields(&self, _item: &ExprListComp, f: &mut PyFormatter) -> FormatResult<()> { + write!(f, [not_yet_implemented_custom_text("[i for i in []]")]) } } diff --git a/crates/ruff_python_formatter/src/expression/expr_slice.rs b/crates/ruff_python_formatter/src/expression/expr_slice.rs index 1bd834374e8d6..35b559f285ccf 100644 --- a/crates/ruff_python_formatter/src/expression/expr_slice.rs +++ b/crates/ruff_python_formatter/src/expression/expr_slice.rs @@ -10,11 +10,10 @@ use rustpython_parser::ast::ExprSlice; pub struct FormatExprSlice; impl FormatNodeRule for FormatExprSlice { - fn fmt_fields(&self, item: &ExprSlice, f: &mut PyFormatter) -> FormatResult<()> { + fn fmt_fields(&self, _item: &ExprSlice, f: &mut PyFormatter) -> FormatResult<()> { write!( f, [not_yet_implemented_custom_text( - item, "NOT_IMPLEMENTED_start:NOT_IMPLEMENTED_end" )] ) diff --git a/crates/ruff_python_formatter/src/expression/expr_subscript.rs b/crates/ruff_python_formatter/src/expression/expr_subscript.rs index e71f31ca8591d..559f747292d1a 100644 --- a/crates/ruff_python_formatter/src/expression/expr_subscript.rs +++ b/crates/ruff_python_formatter/src/expression/expr_subscript.rs @@ -10,11 +10,10 @@ use rustpython_parser::ast::ExprSubscript; pub struct FormatExprSubscript; impl FormatNodeRule for FormatExprSubscript { - fn fmt_fields(&self, item: &ExprSubscript, f: &mut PyFormatter) -> FormatResult<()> { + fn fmt_fields(&self, _item: &ExprSubscript, f: &mut PyFormatter) -> FormatResult<()> { write!( f, [not_yet_implemented_custom_text( - item, "NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]" )] ) diff --git a/crates/ruff_python_formatter/src/expression/expr_tuple.rs b/crates/ruff_python_formatter/src/expression/expr_tuple.rs index 016b88a530e4f..cc83eb33182c3 100644 --- a/crates/ruff_python_formatter/src/expression/expr_tuple.rs +++ b/crates/ruff_python_formatter/src/expression/expr_tuple.rs @@ -9,8 +9,8 @@ use rustpython_parser::ast::ExprTuple; pub struct FormatExprTuple; impl FormatNodeRule for FormatExprTuple { - fn fmt_fields(&self, item: &ExprTuple, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [not_yet_implemented_custom_text(item, "(1, 2)")]) + fn fmt_fields(&self, _item: &ExprTuple, f: &mut PyFormatter) -> FormatResult<()> { + write!(f, [not_yet_implemented_custom_text("(1, 2)")]) } } diff --git a/crates/ruff_python_formatter/src/lib.rs b/crates/ruff_python_formatter/src/lib.rs index 5c2adf9f7f1c4..90dbe79e48811 100644 --- a/crates/ruff_python_formatter/src/lib.rs +++ b/crates/ruff_python_formatter/src/lib.rs @@ -39,19 +39,17 @@ where N: AstNode, { fn fmt(&self, node: &N, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [source_position(node.start())])?; self.fmt_leading_comments(node, f)?; self.fmt_node(node, f)?; self.fmt_dangling_comments(node, f)?; - self.fmt_trailing_comments(node, f)?; - write!(f, [source_position(node.end())]) + self.fmt_trailing_comments(node, f) } /// Formats the node without comments. Ignores any suppression comments. fn fmt_node(&self, node: &N, f: &mut PyFormatter) -> FormatResult<()> { + write!(f, [source_position(node.start())])?; self.fmt_fields(node, f)?; - - Ok(()) + write!(f, [source_position(node.end())]) } /// Formats the node's fields. @@ -164,33 +162,26 @@ impl Format> for NotYetImplemented { } } -pub(crate) struct NotYetImplementedCustomText(NodeKind, String); +pub(crate) struct NotYetImplementedCustomText(&'static str); /// Formats a placeholder for nodes that have not yet been implemented -pub(crate) fn not_yet_implemented_custom_text<'a, T>( - node: T, - text: impl AsRef, -) -> NotYetImplementedCustomText -where - T: Into>, -{ - NotYetImplementedCustomText(node.into().kind(), text.as_ref().to_string()) +pub(crate) const fn not_yet_implemented_custom_text( + text: &'static str, +) -> NotYetImplementedCustomText { + NotYetImplementedCustomText(text) } impl Format> for NotYetImplementedCustomText { fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> { f.write_element(FormatElement::Tag(Tag::StartVerbatim( tag::VerbatimKind::Verbatim { - length: self.1.text_len(), + length: self.0.text_len(), }, )))?; - f.write_element(FormatElement::DynamicText { - text: Box::from(self.1.clone()), - })?; + text(self.0).fmt(f)?; - f.write_element(FormatElement::Tag(Tag::EndVerbatim))?; - Ok(()) + f.write_element(FormatElement::Tag(Tag::EndVerbatim)) } } @@ -417,12 +408,11 @@ Formatted twice: #[ignore] #[test] fn quick_test() { - let src = r#"AAAAAAAAAAAAA = AAAAAAAAAAAAA # type: ignore + let src = r#" +def test(): ... -call_to_some_function_asdf( - foo, - [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore -) +# Comment +def with_leading_comment(): ... "#; // Tokenize once let mut tokens = Vec::new(); 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 671b8e3ab3477..180c446c5f8f9 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 @@ -55,17 +55,17 @@ y = 100(no) +x = NOT_IMPLEMENTED_call() +x = NOT_IMPLEMENTED_call() +x = NOT_IMPLEMENTED_call() -+x = 0x42.NOT_IMPLEMENTED_attr -+x = 0x42.NOT_IMPLEMENTED_attr -+x = 0x42.NOT_IMPLEMENTED_attr ++x = 1. .NOT_IMPLEMENTED_attr ++x = 1E+1 .NOT_IMPLEMENTED_attr ++x = 1E-1 .NOT_IMPLEMENTED_attr +x = NOT_IMPLEMENTED_call() -+x = 0x42.NOT_IMPLEMENTED_attr ++x = 123456789.123456789E123456789 .NOT_IMPLEMENTED_attr +x = NOT_IMPLEMENTED_call() -+x = 0x42.NOT_IMPLEMENTED_attr ++x = 123456789J.NOT_IMPLEMENTED_attr +x = NOT_IMPLEMENTED_call() +x = NOT_IMPLEMENTED_call() +x = NOT_IMPLEMENTED_call() -+x = 0x42.NOT_IMPLEMENTED_attr ++x = 0O777 .NOT_IMPLEMENTED_attr +x = NOT_IMPLEMENTED_call() +x = NOT_YET_IMPLEMENTED_ExprUnaryOp @@ -85,17 +85,17 @@ y = 100(no) x = NOT_IMPLEMENTED_call() x = NOT_IMPLEMENTED_call() x = NOT_IMPLEMENTED_call() -x = 0x42.NOT_IMPLEMENTED_attr -x = 0x42.NOT_IMPLEMENTED_attr -x = 0x42.NOT_IMPLEMENTED_attr +x = 1. .NOT_IMPLEMENTED_attr +x = 1E+1 .NOT_IMPLEMENTED_attr +x = 1E-1 .NOT_IMPLEMENTED_attr x = NOT_IMPLEMENTED_call() -x = 0x42.NOT_IMPLEMENTED_attr +x = 123456789.123456789E123456789 .NOT_IMPLEMENTED_attr x = NOT_IMPLEMENTED_call() -x = 0x42.NOT_IMPLEMENTED_attr +x = 123456789J.NOT_IMPLEMENTED_attr x = NOT_IMPLEMENTED_call() x = NOT_IMPLEMENTED_call() x = NOT_IMPLEMENTED_call() -x = 0x42.NOT_IMPLEMENTED_attr +x = 0O777 .NOT_IMPLEMENTED_attr x = NOT_IMPLEMENTED_call() x = NOT_YET_IMPLEMENTED_ExprUnaryOp 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 523d0975d6902..6105a550164d5 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,7 +84,7 @@ if True: ```diff --- Black +++ Ruff -@@ -1,99 +1,40 @@ +@@ -1,99 +1,46 @@ -import core, time, a +NOT_YET_IMPLEMENTED_StmtImport @@ -115,7 +115,8 @@ if True: - 2, - 3, -} --b = {1, 2, 3} ++a = {1, 2, 3} + b = {1, 2, 3} -c = { - 1, - 2, @@ -128,13 +129,23 @@ if True: - (4, 5, 6), -} -nested_no_trailing_comma = {(1, 2, 3), (4, 5, 6)} --nested_long_lines = [ ++c = {1, 2, 3} ++x = (1, 2) ++y = (1, 2) ++nested = {(1, 2), (1, 2)} ++nested_no_trailing_comma = {(1, 2), (1, 2)} + nested_long_lines = [ - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", - "cccccccccccccccccccccccccccccccccccccccc", - (1, 2, 3), - "dddddddddddddddddddddddddddddddddddddddd", --] ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ (1, 2), ++ "NOT_YET_IMPLEMENTED_STRING", + ] -{ - "oneple": (1,), -} @@ -148,17 +159,9 @@ if True: - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s" - % bar -) -+a = {0x42, 0x42, 0x42} -+b = {0x42, 0x42, 0x42} -+c = {0x42, 0x42, 0x42} -+x = (1, 2) -+y = (1, 2) -+nested = {(1, 2), (1, 2)} -+nested_no_trailing_comma = {(1, 2), (1, 2)} -+nested_long_lines = [0x42, 0x42, 0x42, (1, 2), 0x42] +{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} +{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} -+[0x42, 0x42 % (1, 2)] ++["NOT_YET_IMPLEMENTED_STRING", "NOT_YET_IMPLEMENTED_STRING" % (1, 2)] +x = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} +y = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} +NOT_YET_IMPLEMENTED_StmtAssert @@ -176,7 +179,7 @@ if True: - 2, - 3, -] -+[0x42, 0x42, 0x42] ++[1, 2, 3] -division_result_tuple = (6 / 2,) -print("foo %r", (foo.bar,)) @@ -228,17 +231,23 @@ NOT_YET_IMPLEMENTED_StmtImportFrom # `as` works as well NOT_YET_IMPLEMENTED_StmtImportFrom -a = {0x42, 0x42, 0x42} -b = {0x42, 0x42, 0x42} -c = {0x42, 0x42, 0x42} +a = {1, 2, 3} +b = {1, 2, 3} +c = {1, 2, 3} x = (1, 2) y = (1, 2) nested = {(1, 2), (1, 2)} nested_no_trailing_comma = {(1, 2), (1, 2)} -nested_long_lines = [0x42, 0x42, 0x42, (1, 2), 0x42] +nested_long_lines = [ + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + (1, 2), + "NOT_YET_IMPLEMENTED_STRING", +] {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} -[0x42, 0x42 % (1, 2)] +["NOT_YET_IMPLEMENTED_STRING", "NOT_YET_IMPLEMENTED_STRING" % (1, 2)] x = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} y = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} NOT_YET_IMPLEMENTED_StmtAssert @@ -247,7 +256,7 @@ NOT_YET_IMPLEMENTED_StmtAssert NOT_YET_IMPLEMENTED_StmtFor NOT_YET_IMPLEMENTED_StmtFor -[0x42, 0x42, 0x42] +[1, 2, 3] division_result_tuple = (1, 2) NOT_IMPLEMENTED_call() 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 42cd75b755b5f..e0d172d1c7800 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,7 +178,7 @@ instruction()#comment with bad spacing ```diff --- Black +++ Ruff -@@ -1,173 +1,68 @@ +@@ -1,31 +1,27 @@ -from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( - MyLovelyCompanyTeamProjectComponent, # NOT DRY -) @@ -195,16 +195,16 @@ instruction()#comment with bad spacing - "Any", - "Callable", - "ClassVar", -+ 0x42, -+ 0x42, -+ 0x42, ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", # ABCs (from collections.abc). - "AbstractSet", # collections.abc.Set. - "ByteString", - "Container", -+ 0x42, # collections.abc.Set. -+ 0x42, -+ 0x42, ++ "NOT_YET_IMPLEMENTED_STRING", # collections.abc.Set. ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", # Concrete collection types. - "Counter", - "Deque", @@ -215,39 +215,30 @@ instruction()#comment with bad spacing - "FrozenSet", - "NamedTuple", # Not really a type. - "Generator", -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, # Not really a type. -+ 0x42, ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", # Not really a type. ++ "NOT_YET_IMPLEMENTED_STRING", ] not_shareables = [ - # singletons -- True, -- False, -+ 0x42, -+ 0x42, - NotImplemented, -- ..., -+ 0x42, +@@ -37,129 +33,28 @@ # builtin types and objects type, object, - object(), - Exception(), -- 42, -- 100.0, -- "spam", + NOT_IMPLEMENTED_call(), + NOT_IMPLEMENTED_call(), -+ 0x42, -+ 0x42, -+ 0x42, + 42, + 100.0, +- "spam", ++ "NOT_YET_IMPLEMENTED_STRING", # user-defined types and objects Cheese, - Cheese("Wensleydale"), @@ -308,10 +299,9 @@ instruction()#comment with bad spacing -""", - arg3=True, - ) -+NOT_YET_IMPLEMENTED_StmtFunctionDef - +- - ############################################################################ - +- - call2( - # short - arg1, @@ -346,17 +336,16 @@ instruction()#comment with bad spacing - while True: - if False: - continue -+CONFIG_FILES = [CONFIG_FILE] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final - +- - # 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_StmtClassDef ++NOT_YET_IMPLEMENTED_StmtFunctionDef -CONFIG_FILES = ( @@ -366,16 +355,18 @@ 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: - if parsed.hostname is None or not parsed.hostname.strip(): # type: ignore - pass -- -- ++NOT_YET_IMPLEMENTED_StmtClassDef + + ####################### - ### SECTION COMMENT ### +@@ -167,7 +62,7 @@ ####################### @@ -396,39 +387,39 @@ NOT_YET_IMPLEMENTED_StmtImportFrom __all__ = [ # Super-special typing primitives. - 0x42, - 0x42, - 0x42, + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", # ABCs (from collections.abc). - 0x42, # collections.abc.Set. - 0x42, - 0x42, + "NOT_YET_IMPLEMENTED_STRING", # collections.abc.Set. + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", # Concrete collection types. - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, # Not really a type. - 0x42, + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", # Not really a type. + "NOT_YET_IMPLEMENTED_STRING", ] not_shareables = [ # singletons - 0x42, - 0x42, + True, + False, NotImplemented, - 0x42, + ..., # builtin types and objects type, object, NOT_IMPLEMENTED_call(), NOT_IMPLEMENTED_call(), - 0x42, - 0x42, - 0x42, + 42, + 100.0, + "NOT_YET_IMPLEMENTED_STRING", # user-defined types and objects Cheese, NOT_IMPLEMENTED_call(), 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 9a820590c9d82..2aff58d8babe2 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 @@ -87,40 +87,39 @@ if __name__ == "__main__": --- Black +++ Ruff @@ -1,61 +1,33 @@ --while True: + while True: - if something.changed: - do.stuff() # trailing comment - # Comment belongs to the `if` block. -+while 0x42: + 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) - # and finally we loop around -+NOT_YET_IMPLEMENTED_StmtWith -with open(some_temp_file) as f: - data = f.read() -- ++NOT_YET_IMPLEMENTED_StmtFor + -try: - with open(some_other_file) as w: - w.write(data) -+NOT_YET_IMPLEMENTED_StmtTry ++NOT_YET_IMPLEMENTED_StmtWith -except OSError: - print("problems") -- ++NOT_YET_IMPLEMENTED_StmtTry + -import sys +NOT_YET_IMPLEMENTED_StmtImport @@ -174,7 +173,7 @@ if __name__ == "__main__": ## Ruff Output ```py -while 0x42: +while True: NOT_YET_IMPLEMENTED_StmtIf # This one belongs to the `while` block. 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 81cf1da2a066e..cabf5db3aef6a 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 @@ -246,7 +246,7 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite - "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore - ) -+result = 0x42 # aaa ++result = "NOT_YET_IMPLEMENTED_STRING" # aaa -result = ( # aaa - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" @@ -301,7 +301,7 @@ NOT_YET_IMPLEMENTED_StmtFunctionDef NOT_YET_IMPLEMENTED_StmtFunctionDef -result = 0x42 # aaa +result = "NOT_YET_IMPLEMENTED_STRING" # aaa AAAAAAAAAAAAA = ( [AAAAAAAAAAAAA] 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 ef2abc8de49f3..d7403c7700f6c 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 @@ -41,16 +41,13 @@ def function(a:int=42): -) +NOT_YET_IMPLEMENTED_StmtImportFrom --result = 1 # A simple comment + result = 1 # A simple comment -result = (1,) # Another one -+result = 0x42 # A simple comment +result = (1, 2) # Another one --result = 1 #  type: ignore --result = 1 # This comment is talking about type: ignore + result = 1 #  type: ignore + result = 1 # This comment is talking about type: ignore -square = Square(4) #  type: Optional[Square] -+result = 0x42 #  type: ignore -+result = 0x42 # This comment is talking about type: ignore +square = NOT_IMPLEMENTED_call() #  type: Optional[Square] @@ -70,11 +67,11 @@ def function(a:int=42): ```py NOT_YET_IMPLEMENTED_StmtImportFrom -result = 0x42 # A simple comment +result = 1 # A simple comment result = (1, 2) # Another one -result = 0x42 #  type: ignore -result = 0x42 # This comment is talking about type: ignore +result = 1 #  type: ignore +result = 1 # This comment is talking about type: ignore square = NOT_IMPLEMENTED_call() #  type: Optional[Square] 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 452a60561a2cf..c211d6c77c4dc 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments_py.snap @@ -114,51 +114,50 @@ async def wat(): # Has many lines. Many, many lines. # Many, many, many lines. -"""Module docstring. -+0x42 - +- -Possibly also many, many lines. -""" -+NOT_YET_IMPLEMENTED_StmtImport -+NOT_YET_IMPLEMENTED_StmtImport - +- -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 ++"NOT_YET_IMPLEMENTED_STRING" -try: - import fast -except ImportError: - import slow as fast -- -- ++NOT_YET_IMPLEMENTED_StmtImport ++NOT_YET_IMPLEMENTED_StmtImport + ++NOT_YET_IMPLEMENTED_StmtImport ++NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment + -# Some comment before a function. --y = 1 +NOT_YET_IMPLEMENTED_StmtTry -+y = 0x42 + y = 1 ( # 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 @@ -171,11 +170,11 @@ async def wat(): # 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 @@ -188,12 +187,12 @@ async def wat(): - def __init__(self): - #: Doc comment for instance attribute qux. - self.qux = 3 -- -- self.spam = 4 -- """Docstring for instance attribute spam.""" +NOT_YET_IMPLEMENTED_StmtClassDef +- self.spam = 4 +- """Docstring for instance attribute spam.""" +- #'

This is pweave!

@@ -227,7 +226,7 @@ async def wat(): # # Has many lines. Many, many lines. # Many, many, many lines. -0x42 +"NOT_YET_IMPLEMENTED_STRING" NOT_YET_IMPLEMENTED_StmtImport NOT_YET_IMPLEMENTED_StmtImport @@ -236,7 +235,7 @@ NOT_YET_IMPLEMENTED_StmtImport NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment NOT_YET_IMPLEMENTED_StmtTry -y = 0x42 +y = 1 ( # some strings y # type: ignore 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 58c51f952ead0..a00903018576f 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 @@ -107,7 +107,7 @@ def g(): +++ Ruff @@ -1,89 +1,12 @@ -"""Docstring.""" -+0x42 ++"NOT_YET_IMPLEMENTED_STRING" # leading comment @@ -203,7 +203,7 @@ def g(): ## Ruff Output ```py -0x42 +"NOT_YET_IMPLEMENTED_STRING" # leading comment 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 f6a0e4f35521f..36d363a161078 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,19 +267,19 @@ last_call() ```diff --- Black +++ Ruff -@@ -1,352 +1,247 @@ +@@ -1,5 +1,6 @@ -"some_string" -b"\\xa3" -+0x42 -+0x42 -+0x42 ++... ++"NOT_YET_IMPLEMENTED_STRING" ++b"NOT_YET_IMPLEMENTED_BYTE_STRING" Name --None --True --False --1 --1.0 --1j + None + True +@@ -7,346 +8,240 @@ + 1 + 1.0 + 1j -True or False -True or False or None -True and False @@ -292,11 +292,23 @@ last_call() -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_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 ++NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 ++NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 ++NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 ++NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 ++NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 ++NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 ++NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 ++NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 ++NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 ++NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 ++NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 + 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 @@ -332,29 +344,6 @@ last_call() -({"a": "b"}, (True or False), (+value), "string", b"bytes") or None -() -(1,) -+0x42 -+0x42 -+0x42 -+0x42 -+0x42 -+0x42 -+NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -+NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -+NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -+NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -+NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -+NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -+NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -+NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -+NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -+NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -+NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -+NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -+v1 << 0x42 -+0x42 >> v2 -+0x42 % finished -+0x42 + v2 - v3 * 0x42 ^ 0x42**v6 / 0x42 // 0x42 -+((0x42 + v2) - (v3 * 0x42)) ^ (((0x42**v6) / 0x42) // 0x42) +NOT_YET_IMPLEMENTED_ExprUnaryOp +NOT_YET_IMPLEMENTED_ExprUnaryOp +NOT_YET_IMPLEMENTED_ExprUnaryOp @@ -380,11 +369,11 @@ last_call() +{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} +{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} +{ -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", + (NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false), +} +NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 @@ -396,39 +385,34 @@ last_call() [] -[1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)] [ -- 1, -- 2, -- 3, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ (NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2), -+ (NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2), -+ (NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2), - ] + 1, + 2, + 3, +-] -[*a] -[*range(10)] -[ - *a, -- 4, -- 5, --] + 4, + 5, ++ 6, ++ 7, ++ 8, ++ 9, ++ (NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2), ++ (NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2), ++ (NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2), + ] -[ - 4, - *a, - 5, -] -+[0x42, 0x42, 0x42] ++[1, 2, 3] +[NOT_YET_IMPLEMENTED_ExprStarred] +[NOT_YET_IMPLEMENTED_ExprStarred] -+[NOT_YET_IMPLEMENTED_ExprStarred, 0x42, 0x42] -+[0x42, NOT_YET_IMPLEMENTED_ExprStarred, 0x42] ++[NOT_YET_IMPLEMENTED_ExprStarred, 4, 5] ++[4, NOT_YET_IMPLEMENTED_ExprStarred, 5] [ this_is_a_very_long_variable_which_will_force_a_delimiter_split, element, @@ -475,9 +459,9 @@ last_call() +NOT_IMPLEMENTED_call() +lukasz.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr +NOT_IMPLEMENTED_call() -+0x42.NOT_IMPLEMENTED_attr -+0x42.NOT_IMPLEMENTED_attr -+0x42.NOT_IMPLEMENTED_attr ++1 .NOT_IMPLEMENTED_attr ++1.0 .NOT_IMPLEMENTED_attr ++....NOT_IMPLEMENTED_attr +NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] +NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] +NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] @@ -518,11 +502,11 @@ last_call() { - k: v - for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", + NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false, } -Python3 > Python2 > COBOL @@ -558,15 +542,15 @@ last_call() - float, - dict[str, int], +[ -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, -+ 0x42, ++ 1, ++ 2, ++ 3, ++ 4, ++ 5, ++ 6, ++ 7, ++ 8, ++ 9, + NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2, + NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2, + NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2, @@ -632,24 +616,6 @@ last_call() -} -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() +(1, 2) +(i for i in []) +(i for i in []) @@ -659,7 +625,13 @@ last_call() +{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} +a = (1, 2) +b = (1, 2) -+c = 0x42 + 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 +d = (1, 2) + a + (1, 2) +e = NOT_IMPLEMENTED_call() +f = (1, 2) @@ -668,6 +640,20 @@ last_call() + (coord_names + NOT_IMPLEMENTED_call()) + + NOT_IMPLEMENTED_call() ) +-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 | NOT_IMPLEMENTED_call()) ++ - NOT_IMPLEMENTED_call() + ) +-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( @@ -677,10 +663,7 @@ last_call() - models.Customer.id.asc(), - ) - .all() -+what_is_up_with_those_new_coord_names = ( -+ (coord_names | NOT_IMPLEMENTED_call()) -+ - NOT_IMPLEMENTED_call() - ) +-) -Ø = set() -authors.łukasz.say_thanks() -mapping = { @@ -728,7 +711,19 @@ last_call() -for j in 1 + (2 + 3): - ... -while this and that: -- ... ++NOT_IMPLEMENTED_call() ++NOT_IMPLEMENTED_call() ++NOT_IMPLEMENTED_call() ++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_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2: + ... -for ( - addr_family, - addr_type, @@ -810,19 +805,6 @@ last_call() - >> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n -): - return True -+NOT_IMPLEMENTED_call() -+NOT_IMPLEMENTED_call() -+NOT_IMPLEMENTED_call() -+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_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2: -+ 0x42 +NOT_YET_IMPLEMENTED_StmtFor +a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right +a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right @@ -858,16 +840,16 @@ last_call() ## Ruff Output ```py -0x42 -0x42 -0x42 +... +"NOT_YET_IMPLEMENTED_STRING" +b"NOT_YET_IMPLEMENTED_BYTE_STRING" Name -0x42 -0x42 -0x42 -0x42 -0x42 -0x42 +None +True +False +1 +1.0 +1j NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 @@ -880,11 +862,11 @@ NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 -v1 << 0x42 -0x42 >> v2 -0x42 % finished -0x42 + v2 - v3 * 0x42 ^ 0x42**v6 / 0x42 // 0x42 -((0x42 + v2) - (v3 * 0x42)) ^ (((0x42**v6) / 0x42) // 0x42) +v1 << 2 +1 >> v2 +1 % finished +1 + v2 - v3 * 4 ^ 5**v6 / 7 // 8 +((1 + v2) - (v3 * 4)) ^ (((5**v6) / 7) // 8) NOT_YET_IMPLEMENTED_ExprUnaryOp NOT_YET_IMPLEMENTED_ExprUnaryOp NOT_YET_IMPLEMENTED_ExprUnaryOp @@ -910,11 +892,11 @@ NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} { - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", (NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false), } NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 @@ -924,24 +906,24 @@ NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 (1, 2) [] [ - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, (NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2), (NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2), (NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2), ] -[0x42, 0x42, 0x42] +[1, 2, 3] [NOT_YET_IMPLEMENTED_ExprStarred] [NOT_YET_IMPLEMENTED_ExprStarred] -[NOT_YET_IMPLEMENTED_ExprStarred, 0x42, 0x42] -[0x42, NOT_YET_IMPLEMENTED_ExprStarred, 0x42] +[NOT_YET_IMPLEMENTED_ExprStarred, 4, 5] +[4, NOT_YET_IMPLEMENTED_ExprStarred, 5] [ this_is_a_very_long_variable_which_will_force_a_delimiter_split, element, @@ -975,9 +957,9 @@ NOT_IMPLEMENTED_call() NOT_IMPLEMENTED_call() lukasz.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr NOT_IMPLEMENTED_call() -0x42.NOT_IMPLEMENTED_attr -0x42.NOT_IMPLEMENTED_attr -0x42.NOT_IMPLEMENTED_attr +1 .NOT_IMPLEMENTED_attr +1.0 .NOT_IMPLEMENTED_attr +....NOT_IMPLEMENTED_attr NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] @@ -1016,23 +998,23 @@ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} { - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false, } [ - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2, NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2, NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2, @@ -1048,7 +1030,7 @@ SomeName {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} a = (1, 2) b = (1, 2) -c = 0x42 +c = 1 d = (1, 2) + a + (1, 2) e = NOT_IMPLEMENTED_call() f = (1, 2) @@ -1086,7 +1068,7 @@ NOT_YET_IMPLEMENTED_StmtFor NOT_YET_IMPLEMENTED_StmtFor NOT_YET_IMPLEMENTED_StmtFor while NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2: - 0x42 + ... NOT_YET_IMPLEMENTED_StmtFor a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right 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 8f34843dcad7b..97b5f8d2ce550 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 @@ -57,12 +57,10 @@ def test_calculate_fades(): -import pytest +NOT_YET_IMPLEMENTED_StmtImport --TmSt = 1 --TmEx = 2 -+TmSt = 0x42 -+TmEx = 0x42 -+ + TmSt = 1 + TmEx = 2 ++ # fmt: off # Test data: @@ -112,8 +110,8 @@ def test_calculate_fades(): ```py NOT_YET_IMPLEMENTED_StmtImport -TmSt = 0x42 -TmEx = 0x42 +TmSt = 1 +TmEx = 2 # fmt: off 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 c963def19660e..1d24dd47e2b71 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 @@ -36,7 +36,7 @@ x = [ - 1, 2, - 3, 4, -] -+x = [0x42, 0x42, 0x42, 0x42] ++x = [1, 2, 3, 4] # fmt: on # fmt: off @@ -44,25 +44,24 @@ x = [ - 1, 2, - 3, 4, -] -+x = [0x42, 0x42, 0x42, 0x42] ++x = [1, 2, 3, 4] # fmt: on --x = [1, 2, 3, 4] -+x = [0x42, 0x42, 0x42, 0x42] + x = [1, 2, 3, 4] ``` ## Ruff Output ```py # fmt: off -x = [0x42, 0x42, 0x42, 0x42] +x = [1, 2, 3, 4] # fmt: on # fmt: off -x = [0x42, 0x42, 0x42, 0x42] +x = [1, 2, 3, 4] # fmt: on -x = [0x42, 0x42, 0x42, 0x42] +x = [1, 2, 3, 4] ``` ## 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 ec4af3280f5d4..fdf49c410946a 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 @@ -454,7 +454,7 @@ d={'a':1, -l=[1,2,3] -d={'a':1, - 'b':2} -+l = [0x42, 0x42, 0x42] ++l = [1, 2, 3] +d = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} ``` @@ -532,7 +532,7 @@ NOT_IMPLEMENTED_call() # fmt: off NOT_YET_IMPLEMENTED_ExprYield # No formatting to the end of the file -l = [0x42, 0x42, 0x42] +l = [1, 2, 3] d = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value} ``` 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 0be540c673c3e..79cc4331e467e 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 @@ -16,29 +16,49 @@ l3 = ["I have", "trailing comma", "so I should be braked",] ```diff --- Black +++ Ruff -@@ -1,11 +1,3 @@ --l1 = [ +@@ -1,11 +1,15 @@ + l1 = [ - "This list should be broken up", - "into multiple lines", - "because it is way too long", --] ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", + ] -l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip --l3 = [ ++l2 = [ ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++] # fmt: skip + l3 = [ - "I have", - "trailing comma", - "so I should be braked", --] -+l1 = [0x42, 0x42, 0x42] -+l2 = [0x42, 0x42, 0x42] # fmt: skip -+l3 = [0x42, 0x42, 0x42] ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", ++ "NOT_YET_IMPLEMENTED_STRING", + ] ``` ## Ruff Output ```py -l1 = [0x42, 0x42, 0x42] -l2 = [0x42, 0x42, 0x42] # fmt: skip -l3 = [0x42, 0x42, 0x42] +l1 = [ + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", +] +l2 = [ + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", +] # fmt: skip +l3 = [ + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", + "NOT_YET_IMPLEMENTED_STRING", +] ``` ## 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 c8077fbe92671..1a16430854922 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 @@ -21,33 +21,31 @@ f = ["This is a very long line that should be formatted into a clearer line ", " --- Black +++ Ruff @@ -1,10 +1,7 @@ --a = 3 -+a = 0x42 + a = 3 # fmt: off -b, c = 1, 2 -d = 6 # fmt: skip --e = 5 +(1, 2) = (1, 2) -+d = 0x42 # fmt: skip -+e = 0x42 ++d = 6 # fmt: skip + e = 5 # fmt: on -f = [ - "This is a very long line that should be formatted into a clearer line ", - "by rearranging.", -] -+f = [0x42, 0x42] ++f = ["NOT_YET_IMPLEMENTED_STRING", "NOT_YET_IMPLEMENTED_STRING"] ``` ## Ruff Output ```py -a = 0x42 +a = 3 # fmt: off (1, 2) = (1, 2) -d = 0x42 # fmt: skip -e = 0x42 +d = 6 # fmt: skip +e = 5 # fmt: on -f = [0x42, 0x42] +f = ["NOT_YET_IMPLEMENTED_STRING", "NOT_YET_IMPLEMENTED_STRING"] ``` ## 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 b3068db72d570..6d4c587187ae1 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 @@ -17,23 +17,22 @@ l = [1, 2, 3,] --- Black +++ Ruff @@ -1,7 +1,3 @@ --a = 2 -+a = 0x42 + a = 2 # fmt: skip -l = [ - 1, - 2, - 3, -] -+l = [0x42, 0x42, 0x42] ++l = [1, 2, 3] ``` ## Ruff Output ```py -a = 0x42 +a = 2 # fmt: skip -l = [0x42, 0x42, 0x42] +l = [1, 2, 3] ``` ## 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 89fa0fca4f673..f088f1dd20ff6 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 @@ -20,21 +20,20 @@ d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasu @@ -1,4 +1,4 @@ -a = "this is some code" -b = 5 # fmt:skip --c = 9 # fmt: skip ++a = "NOT_YET_IMPLEMENTED_STRING" ++b = 5 # fmt:skip + c = 9 # fmt: skip -d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip -+a = 0x42 -+b = 0x42 # fmt:skip -+c = 0x42 # fmt: skip -+d = 0x42 # fmt:skip ++d = "NOT_YET_IMPLEMENTED_STRING" # fmt:skip ``` ## Ruff Output ```py -a = 0x42 -b = 0x42 # fmt:skip -c = 0x42 # fmt: skip -d = 0x42 # fmt:skip +a = "NOT_YET_IMPLEMENTED_STRING" +b = 5 # fmt:skip +c = 9 # fmt: skip +d = "NOT_YET_IMPLEMENTED_STRING" # fmt:skip ``` ## 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 index ca3009ffeba46..47305ef7ac241 100644 --- 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 @@ -19,18 +19,17 @@ d = 5 @@ -1,3 +1,3 @@ -a, b = 1, 2 -c = 6 # fmt: skip --d = 5 +(1, 2) = (1, 2) -+c = 0x42 # fmt: skip -+d = 0x42 ++c = 6 # fmt: skip + d = 5 ``` ## Ruff Output ```py (1, 2) = (1, 2) -c = 0x42 # fmt: skip -d = 0x42 +c = 6 # fmt: skip +d = 5 ``` ## 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 7aed5381353eb..4160f7edaf384 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 @@ -64,7 +64,7 @@ __all__ = ( +++ Ruff @@ -1,64 +1,42 @@ -"""The asyncio package, tracking PEP 3156.""" -+0x42 ++"NOT_YET_IMPLEMENTED_STRING" # flake8: noqa @@ -162,7 +162,7 @@ __all__ = ( ## Ruff Output ```py -0x42 +"NOT_YET_IMPLEMENTED_STRING" # flake8: noqa 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 7913025295216..b52d1de815f51 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 @@ -52,7 +52,7 @@ list_of_types = [tuple[int,],] -list_of_types = [ - tuple[int,], -] -+small_list = [0x42] ++small_list = [1] +list_of_types = [NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]] ``` @@ -69,7 +69,7 @@ NOT_YET_IMPLEMENTED_StmtAnnAssign d = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] # Magic commas still work as expected for non-subscripts. -small_list = [0x42] +small_list = [1] list_of_types = [NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]] ``` 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 2914769fd5638..bc44ba7b21e19 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 @@ -110,16 +110,16 @@ return np.divide( -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)] -+a = 0x42**NOT_YET_IMPLEMENTED_ExprUnaryOp -+b = 0x42 ** NOT_IMPLEMENTED_call() ++a = 5**NOT_YET_IMPLEMENTED_ExprUnaryOp ++b = 5 ** NOT_IMPLEMENTED_call() +c = NOT_YET_IMPLEMENTED_ExprUnaryOp -+d = 0x42 ** NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] ++d = 5 ** NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] +e = NOT_IMPLEMENTED_call() -+f = NOT_IMPLEMENTED_call() ** 0x42 ++f = NOT_IMPLEMENTED_call() ** 5 +g = a.NOT_IMPLEMENTED_attr**c.NOT_IMPLEMENTED_attr -+h = 0x42 ** NOT_IMPLEMENTED_call() -+i = NOT_IMPLEMENTED_call() ** 0x42 -+j = NOT_IMPLEMENTED_call().NOT_IMPLEMENTED_attr ** 0x42 ++h = 5 ** NOT_IMPLEMENTED_call() ++i = NOT_IMPLEMENTED_call() ** 5 ++j = NOT_IMPLEMENTED_call().NOT_IMPLEMENTED_attr ** 5 +k = [i for i in []] +l = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right +m = [(1, 2)] @@ -146,16 +146,16 @@ return np.divide( -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)] -+a = 0x42**NOT_YET_IMPLEMENTED_ExprUnaryOp -+b = 0x42 ** NOT_IMPLEMENTED_call() ++a = 5.0**NOT_YET_IMPLEMENTED_ExprUnaryOp ++b = 5.0 ** NOT_IMPLEMENTED_call() +c = NOT_YET_IMPLEMENTED_ExprUnaryOp -+d = 0x42 ** NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] ++d = 5.0 ** NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] +e = NOT_IMPLEMENTED_call() -+f = NOT_IMPLEMENTED_call() ** 0x42 ++f = NOT_IMPLEMENTED_call() ** 5.0 +g = a.NOT_IMPLEMENTED_attr**c.NOT_IMPLEMENTED_attr -+h = 0x42 ** NOT_IMPLEMENTED_call() -+i = NOT_IMPLEMENTED_call() ** 0x42 -+j = NOT_IMPLEMENTED_call().NOT_IMPLEMENTED_attr ** 0x42 ++h = 5.0 ** NOT_IMPLEMENTED_call() ++i = NOT_IMPLEMENTED_call() ** 5.0 ++j = NOT_IMPLEMENTED_call().NOT_IMPLEMENTED_attr ** 5.0 +k = [i for i in []] +l = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right +m = [(1, 2)] @@ -193,16 +193,16 @@ NOT_YET_IMPLEMENTED_StmtFunctionDef NOT_YET_IMPLEMENTED_StmtFunctionDef -a = 0x42**NOT_YET_IMPLEMENTED_ExprUnaryOp -b = 0x42 ** NOT_IMPLEMENTED_call() +a = 5**NOT_YET_IMPLEMENTED_ExprUnaryOp +b = 5 ** NOT_IMPLEMENTED_call() c = NOT_YET_IMPLEMENTED_ExprUnaryOp -d = 0x42 ** NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] +d = 5 ** NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] e = NOT_IMPLEMENTED_call() -f = NOT_IMPLEMENTED_call() ** 0x42 +f = NOT_IMPLEMENTED_call() ** 5 g = a.NOT_IMPLEMENTED_attr**c.NOT_IMPLEMENTED_attr -h = 0x42 ** NOT_IMPLEMENTED_call() -i = NOT_IMPLEMENTED_call() ** 0x42 -j = NOT_IMPLEMENTED_call().NOT_IMPLEMENTED_attr ** 0x42 +h = 5 ** NOT_IMPLEMENTED_call() +i = NOT_IMPLEMENTED_call() ** 5 +j = NOT_IMPLEMENTED_call().NOT_IMPLEMENTED_attr ** 5 k = [i for i in []] l = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right m = [(1, 2)] @@ -212,16 +212,16 @@ p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_ q = [i for i in []] r = x**y -a = 0x42**NOT_YET_IMPLEMENTED_ExprUnaryOp -b = 0x42 ** NOT_IMPLEMENTED_call() +a = 5.0**NOT_YET_IMPLEMENTED_ExprUnaryOp +b = 5.0 ** NOT_IMPLEMENTED_call() c = NOT_YET_IMPLEMENTED_ExprUnaryOp -d = 0x42 ** NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] +d = 5.0 ** NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] e = NOT_IMPLEMENTED_call() -f = NOT_IMPLEMENTED_call() ** 0x42 +f = NOT_IMPLEMENTED_call() ** 5.0 g = a.NOT_IMPLEMENTED_attr**c.NOT_IMPLEMENTED_attr -h = 0x42 ** NOT_IMPLEMENTED_call() -i = NOT_IMPLEMENTED_call() ** 0x42 -j = NOT_IMPLEMENTED_call().NOT_IMPLEMENTED_attr ** 0x42 +h = 5.0 ** NOT_IMPLEMENTED_call() +i = NOT_IMPLEMENTED_call() ** 5.0 +j = NOT_IMPLEMENTED_call().NOT_IMPLEMENTED_attr ** 5.0 k = [i for i in []] l = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right m = [(1, 2)] 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 f7fe8053cef42..b917eaf3b081b 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 @@ -47,7 +47,7 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx -xxxxxxxxx_yyy_zzzzzzzz[ - xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1) -] = 1 -+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] = 0x42 ++NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] = 1 ``` ## Ruff Output @@ -61,7 +61,7 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx # 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. -NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] = 0x42 +NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] = 1 ``` ## 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 bfd0186ca456d..b0d01240b13b2 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 @@ -170,13 +170,13 @@ with open("/path/to/file.txt", mode="r") as read_file: -for i in range(5): - for j in range(7): - print(f"{i}) The lines above me should be removed!") +- +- +-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: -- 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 @@ -188,23 +188,19 @@ with open("/path/to/file.txt", mode="r") as read_file: +NOT_YET_IMPLEMENTED_StmtIf --while True: + while True: - print("The newline above me should be deleted!") -+while 0x42: + NOT_IMPLEMENTED_call() --while True: + while True: - print("The newlines above me should be deleted!") -+while 0x42: + NOT_IMPLEMENTED_call() --while True: -- while False: + while True: + while False: - print("The newlines above me should be deleted!") -+while 0x42: -+ while 0x42: + NOT_IMPLEMENTED_call() @@ -263,16 +259,16 @@ NOT_YET_IMPLEMENTED_StmtIf NOT_YET_IMPLEMENTED_StmtIf -while 0x42: +while True: NOT_IMPLEMENTED_call() -while 0x42: +while True: NOT_IMPLEMENTED_call() -while 0x42: - while 0x42: +while True: + while False: NOT_IMPLEMENTED_call() 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 64bcdd1872de2..3802fc4b75d09 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 @@ -69,10 +69,8 @@ def example8(): --- Black +++ Ruff @@ -1,85 +1,37 @@ --x = 1 --x = 1.2 -+x = 0x42 -+x = 0x42 + x = 1 + x = 1.2 -data = ( - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" @@ -173,8 +171,8 @@ def example8(): ## Ruff Output ```py -x = 0x42 -x = 0x42 +x = 1 +x = 1.2 data = NOT_IMPLEMENTED_call() 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 ca42e024d1140..b0626e0c3149c 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 @@ -74,13 +74,11 @@ func( +d = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] # Remove commas for non-subscripts. --small_list = [1] + small_list = [1] -list_of_types = [tuple[int,]] --small_set = {1} --set_of_types = {tuple[int,]} -+small_list = [0x42] +list_of_types = [NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]] -+small_set = {0x42} + small_set = {1} +-set_of_types = {tuple[int,]} +set_of_types = {NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]} # Except single element tuples @@ -113,9 +111,9 @@ NOT_YET_IMPLEMENTED_StmtAnnAssign d = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key] # Remove commas for non-subscripts. -small_list = [0x42] +small_list = [1] list_of_types = [NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]] -small_set = {0x42} +small_set = {1} set_of_types = {NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]} # Except single element tuples 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 5ddefe528c77c..72a298611219a 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 @@ -41,7 +41,7 @@ def docstring_multiline(): -(b"", b"") -("", "") -(r"", R"") -+name = 0x42 ++name = "NOT_YET_IMPLEMENTED_STRING" +(1, 2) +(1, 2) +(1, 2) @@ -70,7 +70,7 @@ def docstring_multiline(): ```py #!/usr/bin/env python3 -name = 0x42 +name = "NOT_YET_IMPLEMENTED_STRING" (1, 2) (1, 2) (1, 2) 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 4d20cab2cd7ae..fcc9f5767e32d 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,14 +42,15 @@ assert ( ```diff --- Black +++ Ruff -@@ -1,58 +1,17 @@ +@@ -1,58 +1,21 @@ importA --( + ( - () -- << 0 ++ (1, 2) + << 0 - ** 101234234242352525425252352352525234890264906820496920680926538059059209922523523525 --) # -+(1, 2) << 0x42**0x42 # ++ **101234234242352525425252352352525234890264906820496920680926538059059209922523523525 + ) # -assert sort_by_dependency( - { @@ -65,10 +66,8 @@ assert ( +NOT_YET_IMPLEMENTED_StmtAssert importA --0 --0 ^ 0 # -+0x42 -+0x42 ^ 0x42 # + 0 + 0 ^ 0 # -class A: @@ -114,13 +113,17 @@ assert ( ```py importA -(1, 2) << 0x42**0x42 # +( + (1, 2) + << 0 + **101234234242352525425252352352525234890264906820496920680926538059059209922523523525 +) # NOT_YET_IMPLEMENTED_StmtAssert importA -0x42 -0x42 ^ 0x42 # +0 +0 ^ 0 # NOT_YET_IMPLEMENTED_StmtClassDef 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 deleted file mode 100644 index e5215169334e8..0000000000000 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tricky_unicode_symbols_py.snap +++ /dev/null @@ -1,73 +0,0 @@ ---- -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 -+ä = 0x42 -+µ = 0x42 -+蟒 = 0x42 -+x󠄀 = 0x42 -+មុ = 0x42 -+Q̇_per_meter = 0x42 - --A᧚ = 3 --A፩ = 8 -+A᧚ = 0x42 -+A፩ = 0x42 -``` - -## Ruff Output - -```py -ä = 0x42 -µ = 0x42 -蟒 = 0x42 -x󠄀 = 0x42 -មុ = 0x42 -Q̇_per_meter = 0x42 - -A᧚ = 0x42 -A፩ = 0x42 -``` - -## 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__ruff_test__statement__stmt_assign_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__stmt_assign_py.snap index 351d8d690af7f..206324b160cf0 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__stmt_assign_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__stmt_assign_py.snap @@ -22,15 +22,15 @@ a = asdf = fjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfalflaflapamsakjsdhflakj ```py # break left hand side a1akjdshflkjahdslkfjlasfdahjlfds = bakjdshflkjahdslkfjlasfdahjlfds = cakjdshflkjahdslkfjlasfdahjlfds = kjaödkjaföjfahlfdalfhaöfaöfhaöfha = fkjaödkjaföjfahlfdalfhaöfaöfhaöfha = g = ( - 0x42 + 3 ) # join left hand side -a2 = (b2) = 0x42 +a2 = (b2) = 2 # Break the last element a = asdf = fjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfal = ( - 0x42 + 1 ) ``` 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 451e344eae9f5..fd9f812cda57e 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,7 +40,7 @@ while ( ## Output ```py -while 0x42: # trailing test comment +while 34: # trailing test comment NOT_YET_IMPLEMENTED_StmtPass # trailing last statement comment # trailing while body comment @@ -59,7 +59,7 @@ while ( NOT_YET_IMPLEMENTED_StmtPass else: - 0x42 + ... while NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2: # comment NOT_IMPLEMENTED_call() 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 3e885e5336fdf..a103d8ccaee40 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,11 +44,11 @@ e = 50 # one empty line before ```py # Removes the line above -a = 0x42 # Keeps the line above +a = 10 # Keeps the line above # Separated by one line from `a` and `b` -b = 0x42 +b = 20 # Adds two lines after `b` @@ -57,22 +57,22 @@ NOT_YET_IMPLEMENTED_StmtClassDef # two lines before, one line after -c = 0x42 +c = 30 while NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: - 0x42 + ... # trailing comment with one line before # one line before this leading comment -d = 0x42 +d = 40 while NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: - 0x42 + ... # no empty line before -e = 0x42 # one empty line before +e = 50 # one empty line before ``` diff --git a/crates/ruff_python_formatter/src/statement/suite.rs b/crates/ruff_python_formatter/src/statement/suite.rs index 09af43c6abf88..d80bb55803794 100644 --- a/crates/ruff_python_formatter/src/statement/suite.rs +++ b/crates/ruff_python_formatter/src/statement/suite.rs @@ -234,22 +234,22 @@ def trailing_func(): assert_eq!( formatted, - r#"a = 0x42 + r#"a = 10 -three_leading_newlines = 0x42 +three_leading_newlines = 80 -two_leading_newlines = 0x42 +two_leading_newlines = 20 -one_leading_newline = 0x42 -no_leading_newline = 0x42 +one_leading_newline = 10 +no_leading_newline = 30 NOT_YET_IMPLEMENTED_StmtClassDef -trailing_statement = 0x42 +trailing_statement = 1 NOT_YET_IMPLEMENTED_StmtFunctionDef @@ -265,18 +265,18 @@ NOT_YET_IMPLEMENTED_StmtFunctionDef"# assert_eq!( formatted, - r#"a = 0x42 + r#"a = 10 -three_leading_newlines = 0x42 +three_leading_newlines = 80 -two_leading_newlines = 0x42 +two_leading_newlines = 20 -one_leading_newline = 0x42 -no_leading_newline = 0x42 +one_leading_newline = 10 +no_leading_newline = 30 NOT_YET_IMPLEMENTED_StmtClassDef -trailing_statement = 0x42 +trailing_statement = 1 NOT_YET_IMPLEMENTED_StmtFunctionDef