From 66089e1a2e4b8b6ad6de3dc9543cd9a8d2a764e3 Mon Sep 17 00:00:00 2001 From: konstin Date: Thu, 15 Jun 2023 13:24:14 +0200 Subject: [PATCH] Fix a number of formatter errors from the cpython repository (#5089) ## Summary This fixes a number of problems in the formatter that showed up with various files in the [cpython](https://github.com/python/cpython) repository. These problems surfaced as unstable formatting and invalid code. This is not the entirety of problems discovered through cpython, but a big enough chunk to separate it. Individual fixes are generally individual commits. They were discovered with #5055, which i update as i work through the output ## Test Plan I added regression tests with links to cpython for each entry, except for the two stubs that also got comment stubs since they'll be implemented properly later. --- crates/ruff_python_ast/src/node.rs | 16 +++++++ .../{binary_expression.py => binary.py} | 0 .../test/fixtures/ruff/expression/list.py | 10 ++++ .../{tuple_expression.py => tuple.py} | 0 .../statement/{stmt_assign.py => assign.py} | 0 .../test/fixtures/ruff/statement/function.py | 22 +++++++++ .../ruff/statement/{if_statement.py => if.py} | 0 .../src/comments/placement.rs | 22 ++++++++- .../src/expression/expr_constant.rs | 16 +++++++ .../src/expression/expr_dict.rs | 11 +++++ .../src/expression/expr_list.rs | 39 ++++++++++++++-- .../src/other/arguments.rs | 5 ++ ...atter__tests__black_test__fmtonoff_py.snap | 20 ++++---- ...atter__tests__black_test__function_py.snap | 5 +- ...ts__ruff_test__expression__binary_py.snap} | 0 ...tests__ruff_test__expression__list_py.snap | 35 ++++++++++++++ ...sts__ruff_test__expression__tuple_py.snap} | 0 ...sts__ruff_test__statement__assign_py.snap} | 0 ...ts__ruff_test__statement__function_py.snap | 46 +++++++++++++++++++ ...__tests__ruff_test__statement__if_py.snap} | 0 ...matter__trivia__tests__tokenize_comma.snap | 2 +- ..._trivia__tests__tokenize_continuation.snap | 2 +- ...__trivia__tests__tokenize_parentheses.snap | 2 +- ...er__trivia__tests__tokenize_substring.snap | 2 +- ...atter__trivia__tests__tokenize_trivia.snap | 2 +- 25 files changed, 234 insertions(+), 23 deletions(-) rename crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/{binary_expression.py => binary.py} (100%) create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list.py rename crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/{tuple_expression.py => tuple.py} (100%) rename crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/{stmt_assign.py => assign.py} (100%) rename crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/{if_statement.py => if.py} (100%) rename crates/ruff_python_formatter/src/snapshots/{ruff_python_formatter__tests__ruff_test__expression__binary_expression_py.snap => ruff_python_formatter__tests__ruff_test__expression__binary_py.snap} (100%) create mode 100644 crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__list_py.snap rename crates/ruff_python_formatter/src/snapshots/{ruff_python_formatter__tests__ruff_test__expression__tuple_expression_py.snap => ruff_python_formatter__tests__ruff_test__expression__tuple_py.snap} (100%) rename crates/ruff_python_formatter/src/snapshots/{ruff_python_formatter__tests__ruff_test__statement__stmt_assign_py.snap => ruff_python_formatter__tests__ruff_test__statement__assign_py.snap} (100%) rename crates/ruff_python_formatter/src/snapshots/{ruff_python_formatter__tests__ruff_test__statement__if_statement_py.snap => ruff_python_formatter__tests__ruff_test__statement__if_py.snap} (100%) diff --git a/crates/ruff_python_ast/src/node.rs b/crates/ruff_python_ast/src/node.rs index 1c8d66ee51..d60be5b284 100644 --- a/crates/ruff_python_ast/src/node.rs +++ b/crates/ruff_python_ast/src/node.rs @@ -4212,6 +4212,22 @@ impl AnyNodeRef<'_> { | AnyNodeRef::Decorator(_) => false, } } + + pub const fn is_node_with_body(self) -> bool { + matches!( + self, + AnyNodeRef::StmtIf(_) + | AnyNodeRef::StmtFor(_) + | AnyNodeRef::StmtAsyncFor(_) + | AnyNodeRef::StmtWhile(_) + | AnyNodeRef::StmtWith(_) + | AnyNodeRef::StmtAsyncWith(_) + | AnyNodeRef::StmtMatch(_) + | AnyNodeRef::StmtFunctionDef(_) + | AnyNodeRef::StmtAsyncFunctionDef(_) + | AnyNodeRef::StmtClassDef(_) + ) + } } impl<'a> From<&'a ModModule> for AnyNodeRef<'a> { diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary_expression.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary.py similarity index 100% rename from crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary_expression.py rename to crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary.py diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list.py new file mode 100644 index 0000000000..2ec1c0e293 --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list.py @@ -0,0 +1,10 @@ +# Dangling comment placement in empty lists +# Regression test for https://github.com/python/cpython/blob/03160630319ca26dcbbad65225da4248e54c45ec/Tools/c-analyzer/c_analyzer/datafiles.py#L14-L16 +a1 = [ # a +] +a2 = [ # a + # b +] +a3 = [ + # b +] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/tuple_expression.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/tuple.py similarity index 100% rename from crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/tuple_expression.py rename to crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/tuple.py diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/stmt_assign.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/assign.py similarity index 100% rename from crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/stmt_assign.py rename to crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/assign.py diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/function.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/function.py index 7e4ddaa48b..8b540fe646 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/function.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/function.py @@ -68,3 +68,25 @@ def test(): ... # Comment def with_leading_comment(): ... + +# Comment that could be mistaken for a trailing comment of the function declaration when +# looking from the position of the if +# Regression test for https://github.com/python/cpython/blob/ad56340b665c5d8ac1f318964f71697bba41acb7/Lib/logging/__init__.py#L253-L260 +if True: + def f1(): + pass # a +else: + pass + +# Here it's actually a trailing comment +if True: + def f2(): + pass + # a +else: + pass + +# Make sure the star is printed +# Regression test for https://github.com/python/cpython/blob/7199584ac8632eab57612f595a7162ab8d2ebbc0/Lib/warnings.py#L513 +def f(arg1=1, *, kwonlyarg1, kwonlyarg2=2): + pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/if_statement.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/if.py similarity index 100% rename from crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/if_statement.py rename to crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/if.py diff --git a/crates/ruff_python_formatter/src/comments/placement.rs b/crates/ruff_python_formatter/src/comments/placement.rs index 2dabe23930..3c1166b1f5 100644 --- a/crates/ruff_python_formatter/src/comments/placement.rs +++ b/crates/ruff_python_formatter/src/comments/placement.rs @@ -332,7 +332,20 @@ fn handle_in_between_bodies_end_of_line_comment<'a>( // else: // b // ``` - CommentPlacement::trailing(preceding, comment) + if preceding.is_node_with_body() { + // We can't set this as a trailing comment of the function declaration because it + // will then move behind the function block instead of sticking with the pass + // ```python + // if True: + // def f(): + // pass # a + // else: + // pass + // ``` + CommentPlacement::Default(comment) + } else { + CommentPlacement::trailing(preceding, comment) + } } else if following.is_stmt_if() || following.is_except_handler() { // The `elif` or except handlers have their own body to which we can attach the trailing comment // ```python @@ -837,7 +850,12 @@ fn find_pos_only_slash_offset( return Some(maybe_slash.start()); } - debug_assert_eq!(maybe_slash.kind(), TokenKind::RParen); + debug_assert_eq!( + maybe_slash.kind(), + TokenKind::RParen, + "{:?}", + maybe_slash.kind() + ); } } diff --git a/crates/ruff_python_formatter/src/expression/expr_constant.rs b/crates/ruff_python_formatter/src/expression/expr_constant.rs index 90ee45c1cf..bdb9b7117c 100644 --- a/crates/ruff_python_formatter/src/expression/expr_constant.rs +++ b/crates/ruff_python_formatter/src/expression/expr_constant.rs @@ -39,6 +39,22 @@ impl FormatNodeRule for FormatExprConstant { } } } + + fn fmt_dangling_comments( + &self, + _node: &ExprConstant, + _f: &mut PyFormatter, + ) -> FormatResult<()> { + // TODO(konstin): Reactivate when string formatting works, currently a source of unstable + // formatting, e.g.: + // magic_methods = ( + // "enter exit " + // # we added divmod and rdivmod here instead of numerics + // # because there is no idivmod + // "divmod rdivmod neg pos abs invert " + // ) + Ok(()) + } } impl NeedsParentheses for ExprConstant { diff --git a/crates/ruff_python_formatter/src/expression/expr_dict.rs b/crates/ruff_python_formatter/src/expression/expr_dict.rs index 600841f2da..3ccc6a4dc8 100644 --- a/crates/ruff_python_formatter/src/expression/expr_dict.rs +++ b/crates/ruff_python_formatter/src/expression/expr_dict.rs @@ -18,6 +18,17 @@ impl FormatNodeRule for FormatExprDict { )] ) } + + fn fmt_dangling_comments(&self, _node: &ExprDict, _f: &mut PyFormatter) -> FormatResult<()> { + // TODO(konstin): Reactivate when string formatting works, currently a source of unstable + // formatting, e.g. + // ```python + // coverage_ignore_c_items = { + // # 'cfunction': [...] + // } + // ``` + Ok(()) + } } impl NeedsParentheses for ExprDict { diff --git a/crates/ruff_python_formatter/src/expression/expr_list.rs b/crates/ruff_python_formatter/src/expression/expr_list.rs index 20153d8aa7..a269853579 100644 --- a/crates/ruff_python_formatter/src/expression/expr_list.rs +++ b/crates/ruff_python_formatter/src/expression/expr_list.rs @@ -1,4 +1,4 @@ -use crate::comments::{dangling_comments, Comments}; +use crate::comments::{dangling_comments, CommentTextPosition, Comments}; use crate::expression::parentheses::{ default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, }; @@ -18,6 +18,39 @@ impl FormatNodeRule for FormatExprList { ctx: _, } = item; + let comments = f.context().comments().clone(); + let dangling = comments.dangling_comments(item.into()); + + // The empty list is special because there can be dangling comments, and they can be in two + // positions: + // ```python + // a3 = [ # end-of-line + // # own line + // ] + // ``` + // In all other cases comments get assigned to a list element + if elts.is_empty() { + let end_of_line_split = dangling + .partition_point(|comment| comment.position() == CommentTextPosition::EndOfLine); + debug_assert!(dangling[end_of_line_split..] + .iter() + .all(|comment| comment.position() == CommentTextPosition::OwnLine)); + return write!( + f, + [group(&format_args![ + text("["), + dangling_comments(&dangling[..end_of_line_split]), + soft_block_indent(&dangling_comments(&dangling[end_of_line_split..])), + text("]") + ])] + ); + } + + debug_assert!( + dangling.is_empty(), + "A non-empty expression list has dangling comments" + ); + let items = format_with(|f| { let mut iter = elts.iter(); @@ -36,14 +69,10 @@ impl FormatNodeRule for FormatExprList { Ok(()) }); - let comments = f.context().comments().clone(); - let dangling = comments.dangling_comments(item.into()); - write!( f, [group(&format_args![ text("["), - dangling_comments(dangling), soft_block_indent(&items), text("]") ])] diff --git a/crates/ruff_python_formatter/src/other/arguments.rs b/crates/ruff_python_formatter/src/other/arguments.rs index 19f8107f00..9e0e88e214 100644 --- a/crates/ruff_python_formatter/src/other/arguments.rs +++ b/crates/ruff_python_formatter/src/other/arguments.rs @@ -58,6 +58,9 @@ impl FormatNodeRule for FormatArguments { last_node = Some(default.map_or_else(|| argument.into(), AnyNodeRef::from)); } + // kw only args need either a `*args` ahead of them capturing all var args or a `*` + // pseudo-argument capturing all fields. We can also have `*args` without any kwargs + // afterwards. if let Some(vararg) = vararg { joiner.entry(&format_args![ leading_node_comments(vararg.as_ref()), @@ -65,6 +68,8 @@ impl FormatNodeRule for FormatArguments { vararg.format() ]); last_node = Some(vararg.as_any_node_ref()); + } else if !kwonlyargs.is_empty() { + joiner.entry(&text("*")); } debug_assert!(defaults.next().is_none()); 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 7a3cedbd0b..183ed478e1 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff_py.snap @@ -222,7 +222,7 @@ d={'a':1, # Comment 1 # Comment 2 -@@ -18,109 +16,111 @@ +@@ -18,109 +16,112 @@ # fmt: off def func_no_args(): @@ -269,6 +269,7 @@ d={'a':1, + number: int, + no_annotation=None, + text: str = "NOT_YET_IMPLEMENTED_STRING", ++ *, + debug: bool = False, + **kwargs, +) -> str: @@ -393,7 +394,7 @@ d={'a':1, # fmt: off # hey, that won't work -@@ -130,13 +130,15 @@ +@@ -130,13 +131,15 @@ def on_and_off_broken(): @@ -414,7 +415,7 @@ d={'a':1, # fmt: on # fmt: off # ...but comments still get reformatted even though they should not be -@@ -145,80 +147,21 @@ +@@ -145,80 +148,21 @@ def long_lines(): if True: @@ -426,13 +427,11 @@ d={'a':1, - implicit_default=True, - ) - ) -+ NOT_IMPLEMENTED_call() - # fmt: off +- # fmt: off - a = ( - unnecessary_bracket() - ) -+ a = NOT_IMPLEMENTED_call() - # fmt: on +- # fmt: on - _type_comment_re = re.compile( - r""" - ^ @@ -453,9 +452,11 @@ d={'a':1, - ) - $ - """, -- # fmt: off ++ NOT_IMPLEMENTED_call() + # fmt: off - re.MULTILINE|re.VERBOSE -- # fmt: on ++ a = NOT_IMPLEMENTED_call() + # fmt: on - ) + _type_comment_re = NOT_IMPLEMENTED_call() @@ -550,6 +551,7 @@ def function_signature_stress_test( number: int, no_annotation=None, text: str = "NOT_YET_IMPLEMENTED_STRING", + *, debug: bool = False, **kwargs, ) -> str: 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 1ae6f9a66b..9f5f58ae76 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 @@ -126,7 +126,7 @@ def __await__(): return (yield) def func_no_args(): -@@ -14,135 +13,86 @@ +@@ -14,135 +13,87 @@ b c if True: @@ -161,8 +161,8 @@ def __await__(): return (yield) number: int, no_annotation=None, - text: str = "default", -- *, + text: str = "NOT_YET_IMPLEMENTED_STRING", + *, debug: bool = False, **kwargs, ) -> str: @@ -339,6 +339,7 @@ def function_signature_stress_test( number: int, no_annotation=None, text: str = "NOT_YET_IMPLEMENTED_STRING", + *, debug: bool = False, **kwargs, ) -> str: 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_py.snap similarity index 100% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__binary_expression_py.snap rename to crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__binary_py.snap diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__list_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__list_py.snap new file mode 100644 index 0000000000..6ecef01df1 --- /dev/null +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__list_py.snap @@ -0,0 +1,35 @@ +--- +source: crates/ruff_python_formatter/src/lib.rs +expression: snapshot +--- +## Input +```py +# Dangling comment placement in empty lists +# Regression test for https://github.com/python/cpython/blob/03160630319ca26dcbbad65225da4248e54c45ec/Tools/c-analyzer/c_analyzer/datafiles.py#L14-L16 +a1 = [ # a +] +a2 = [ # a + # b +] +a3 = [ + # b +] +``` + + + +## Output +```py +# Dangling comment placement in empty lists +# Regression test for https://github.com/python/cpython/blob/03160630319ca26dcbbad65225da4248e54c45ec/Tools/c-analyzer/c_analyzer/datafiles.py#L14-L16 +a1 = [ # a +] +a2 = [ # a + # b +] +a3 = [ + # b +] +``` + + diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__tuple_expression_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__tuple_py.snap similarity index 100% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__tuple_expression_py.snap rename to crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__expression__tuple_py.snap 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__assign_py.snap similarity index 100% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__stmt_assign_py.snap rename to crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__assign_py.snap diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__function_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__function_py.snap index 3d448396f6..ad063ab680 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__function_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__function_py.snap @@ -74,6 +74,28 @@ def test(): ... # Comment def with_leading_comment(): ... + +# Comment that could be mistaken for a trailing comment of the function declaration when +# looking from the position of the if +# Regression test for https://github.com/python/cpython/blob/ad56340b665c5d8ac1f318964f71697bba41acb7/Lib/logging/__init__.py#L253-L260 +if True: + def f1(): + pass # a +else: + pass + +# Here it's actually a trailing comment +if True: + def f2(): + pass + # a +else: + pass + +# Make sure the star is printed +# Regression test for https://github.com/python/cpython/blob/7199584ac8632eab57612f595a7162ab8d2ebbc0/Lib/warnings.py#L513 +def f(arg1=1, *, kwonlyarg1, kwonlyarg2=2): + pass ``` @@ -177,6 +199,30 @@ def test(): # Comment def with_leading_comment(): ... + + +# Comment that could be mistaken for a trailing comment of the function declaration when +# looking from the position of the if +# Regression test for https://github.com/python/cpython/blob/ad56340b665c5d8ac1f318964f71697bba41acb7/Lib/logging/__init__.py#L253-L260 +if True: + def f1(): + pass # a +else: + pass + +# Here it's actually a trailing comment +if True: + def f2(): + pass + # a +else: + pass + + +# Make sure the star is printed +# Regression test for https://github.com/python/cpython/blob/7199584ac8632eab57612f595a7162ab8d2ebbc0/Lib/warnings.py#L513 +def f(arg1=1, *, kwonlyarg1, kwonlyarg2=2): + pass ``` diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__if_statement_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__if_py.snap similarity index 100% rename from crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__if_statement_py.snap rename to crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__if_py.snap diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_comma.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_comma.snap index aade2db2c9..38d1fed60a 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_comma.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_comma.snap @@ -1,6 +1,6 @@ --- source: crates/ruff_python_formatter/src/trivia.rs -expression: tokens +expression: test_case.tokens() --- [ Token { diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_continuation.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_continuation.snap index b537ae611c..83079fe81a 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_continuation.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_continuation.snap @@ -1,6 +1,6 @@ --- source: crates/ruff_python_formatter/src/trivia.rs -expression: tokens +expression: test_case.tokens() --- [ Token { diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_parentheses.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_parentheses.snap index f9de9526ae..ccd6969c2d 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_parentheses.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_parentheses.snap @@ -1,6 +1,6 @@ --- source: crates/ruff_python_formatter/src/trivia.rs -expression: tokens +expression: test_case.tokens() --- [ Token { diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_substring.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_substring.snap index 747d504c4b..181b438c3f 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_substring.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_substring.snap @@ -1,6 +1,6 @@ --- source: crates/ruff_python_formatter/src/trivia.rs -expression: tokens +expression: test_case.tokens() --- [ Token { diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_trivia.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_trivia.snap index 685a032be7..f1d708d6cb 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_trivia.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__trivia__tests__tokenize_trivia.snap @@ -1,6 +1,6 @@ --- source: crates/ruff_python_formatter/src/trivia.rs -expression: tokens +expression: test_case.tokens() --- [ Token {