mirror of
				https://github.com/astral-sh/ruff.git
				synced 2025-11-04 05:34:07 +00:00 
			
		
		
		
	Remove prelude from ruff_python_ast (#5369)
				
					
				
			## Summary Per @MichaReiser, this is causing more confusion than it is helpful.
This commit is contained in:
		
							parent
							
								
									baa7264ca4
								
							
						
					
					
						commit
						fa1b85b3da
					
				
					 28 changed files with 688 additions and 656 deletions
				
			
		| 
						 | 
					@ -3,7 +3,7 @@ use rustpython_parser::ast::{Expr, Ranged};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ruff_diagnostics::{Diagnostic, Violation};
 | 
					use ruff_diagnostics::{Diagnostic, Violation};
 | 
				
			||||||
use ruff_macros::{derive_message_formats, violation};
 | 
					use ruff_macros::{derive_message_formats, violation};
 | 
				
			||||||
use ruff_python_ast::prelude::Constant;
 | 
					use rustpython_parser::ast::Constant;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::checkers::ast::Checker;
 | 
					use crate::checkers::ast::Checker;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ use rustpython_parser::ast::Expr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ruff_diagnostics::{Diagnostic, Violation};
 | 
					use ruff_diagnostics::{Diagnostic, Violation};
 | 
				
			||||||
use ruff_macros::{derive_message_formats, violation};
 | 
					use ruff_macros::{derive_message_formats, violation};
 | 
				
			||||||
use ruff_python_ast::prelude::Ranged;
 | 
					use rustpython_parser::ast::Ranged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::checkers::ast::Checker;
 | 
					use crate::checkers::ast::Checker;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,8 +3,8 @@ use rustpython_parser::ast::{Ranged, Stmt};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ruff_diagnostics::{Diagnostic, Violation};
 | 
					use ruff_diagnostics::{Diagnostic, Violation};
 | 
				
			||||||
use ruff_macros::{derive_message_formats, violation};
 | 
					use ruff_macros::{derive_message_formats, violation};
 | 
				
			||||||
use ruff_python_ast::prelude::Expr;
 | 
					 | 
				
			||||||
use ruff_python_semantic::{Definition, Member, MemberKind};
 | 
					use ruff_python_semantic::{Definition, Member, MemberKind};
 | 
				
			||||||
 | 
					use rustpython_parser::ast::Expr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::checkers::ast::Checker;
 | 
					use crate::checkers::ast::Checker;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ use rustpython_parser::ast::Ranged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ruff_diagnostics::{Diagnostic, Violation};
 | 
					use ruff_diagnostics::{Diagnostic, Violation};
 | 
				
			||||||
use ruff_macros::{derive_message_formats, violation};
 | 
					use ruff_macros::{derive_message_formats, violation};
 | 
				
			||||||
use ruff_python_ast::prelude::Arguments;
 | 
					use rustpython_parser::ast::Arguments;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::checkers::ast::Checker;
 | 
					use crate::checkers::ast::Checker;
 | 
				
			||||||
use crate::settings::types::PythonVersion::Py311;
 | 
					use crate::settings::types::PythonVersion::Py311;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@ use std::fmt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use anyhow::Result;
 | 
					use anyhow::Result;
 | 
				
			||||||
use ruff_text_size::{TextLen, TextRange, TextSize};
 | 
					use ruff_text_size::{TextLen, TextRange, TextSize};
 | 
				
			||||||
 | 
					use rustpython_parser::ast::Decorator;
 | 
				
			||||||
use rustpython_parser::ast::{self, ArgWithDefault, Arguments, Expr, Keyword, Ranged, Stmt};
 | 
					use rustpython_parser::ast::{self, ArgWithDefault, Arguments, Expr, Keyword, Ranged, Stmt};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Violation};
 | 
					use ruff_diagnostics::{AlwaysAutofixableViolation, Violation};
 | 
				
			||||||
| 
						 | 
					@ -10,7 +11,6 @@ use ruff_macros::{derive_message_formats, violation};
 | 
				
			||||||
use ruff_python_ast::call_path::collect_call_path;
 | 
					use ruff_python_ast::call_path::collect_call_path;
 | 
				
			||||||
use ruff_python_ast::helpers::collect_arg_names;
 | 
					use ruff_python_ast::helpers::collect_arg_names;
 | 
				
			||||||
use ruff_python_ast::identifier::Identifier;
 | 
					use ruff_python_ast::identifier::Identifier;
 | 
				
			||||||
use ruff_python_ast::prelude::Decorator;
 | 
					 | 
				
			||||||
use ruff_python_ast::source_code::Locator;
 | 
					use ruff_python_ast::source_code::Locator;
 | 
				
			||||||
use ruff_python_ast::visitor;
 | 
					use ruff_python_ast::visitor;
 | 
				
			||||||
use ruff_python_ast::visitor::Visitor;
 | 
					use ruff_python_ast::visitor::Visitor;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ use rustpython_parser::ast::{Expr, StmtClassDef};
 | 
				
			||||||
use ruff_diagnostics::{Diagnostic, Violation};
 | 
					use ruff_diagnostics::{Diagnostic, Violation};
 | 
				
			||||||
use ruff_macros::{derive_message_formats, violation};
 | 
					use ruff_macros::{derive_message_formats, violation};
 | 
				
			||||||
use ruff_python_ast::identifier::Identifier;
 | 
					use ruff_python_ast::identifier::Identifier;
 | 
				
			||||||
use ruff_python_ast::prelude::Stmt;
 | 
					use rustpython_parser::ast::Stmt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::checkers::ast::Checker;
 | 
					use crate::checkers::ast::Checker;
 | 
				
			||||||
use crate::rules::flake8_slots::rules::helpers::has_slots;
 | 
					use crate::rules::flake8_slots::rules::helpers::has_slots;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,8 +6,8 @@ use rustpython_parser::{ast, lexer, Mode, Tok};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
 | 
					use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
 | 
				
			||||||
use ruff_macros::{derive_message_formats, violation};
 | 
					use ruff_macros::{derive_message_formats, violation};
 | 
				
			||||||
use ruff_python_ast::prelude::Ranged;
 | 
					 | 
				
			||||||
use ruff_python_ast::source_code::Locator;
 | 
					use ruff_python_ast::source_code::Locator;
 | 
				
			||||||
 | 
					use rustpython_parser::ast::Ranged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::checkers::ast::Checker;
 | 
					use crate::checkers::ast::Checker;
 | 
				
			||||||
use crate::registry::AsRule;
 | 
					use crate::registry::AsRule;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@ use rustpython_parser::ast::{self, Expr};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
 | 
					use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
 | 
				
			||||||
use ruff_macros::{derive_message_formats, violation};
 | 
					use ruff_macros::{derive_message_formats, violation};
 | 
				
			||||||
use ruff_python_ast::prelude::Stmt;
 | 
					use rustpython_parser::ast::Stmt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::checkers::ast::Checker;
 | 
					use crate::checkers::ast::Checker;
 | 
				
			||||||
use crate::registry::AsRule;
 | 
					use crate::registry::AsRule;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,7 +9,6 @@ pub mod helpers;
 | 
				
			||||||
pub mod identifier;
 | 
					pub mod identifier;
 | 
				
			||||||
pub mod imports;
 | 
					pub mod imports;
 | 
				
			||||||
pub mod node;
 | 
					pub mod node;
 | 
				
			||||||
pub mod prelude;
 | 
					 | 
				
			||||||
pub mod relocate;
 | 
					pub mod relocate;
 | 
				
			||||||
pub mod source_code;
 | 
					pub mod source_code;
 | 
				
			||||||
pub mod statement_visitor;
 | 
					pub mod statement_visitor;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
					@ -1,3 +0,0 @@
 | 
				
			||||||
pub use crate::node::AstNode;
 | 
					 | 
				
			||||||
pub use rustpython_ast::*;
 | 
					 | 
				
			||||||
pub use rustpython_parser::*;
 | 
					 | 
				
			||||||
| 
						 | 
					@ -2,10 +2,9 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub mod preorder;
 | 
					pub mod preorder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use rustpython_ast::Decorator;
 | 
					 | 
				
			||||||
use rustpython_parser::ast::{
 | 
					use rustpython_parser::ast::{
 | 
				
			||||||
    self, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant, ExceptHandler, Expr,
 | 
					    self, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant, Decorator, ExceptHandler,
 | 
				
			||||||
    ExprContext, Keyword, MatchCase, Operator, Pattern, Stmt, UnaryOp, WithItem,
 | 
					    Expr, ExprContext, Keyword, MatchCase, Operator, Pattern, Stmt, UnaryOp, WithItem,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// A trait for AST visitors. Visits all nodes in the AST recursively in evaluation-order.
 | 
					/// A trait for AST visitors. Visits all nodes in the AST recursively in evaluation-order.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,8 @@
 | 
				
			||||||
use crate::prelude::*;
 | 
					use rustpython_ast::{ArgWithDefault, Mod, TypeIgnore};
 | 
				
			||||||
 | 
					use rustpython_parser::ast::{
 | 
				
			||||||
 | 
					    self, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant, Decorator, ExceptHandler,
 | 
				
			||||||
 | 
					    Expr, Keyword, MatchCase, Operator, Pattern, Stmt, UnaryOp, WithItem,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Visitor that traverses all nodes recursively in pre-order.
 | 
					/// Visitor that traverses all nodes recursively in pre-order.
 | 
				
			||||||
pub trait PreorderVisitor<'a> {
 | 
					pub trait PreorderVisitor<'a> {
 | 
				
			||||||
| 
						 | 
					@ -100,7 +104,7 @@ where
 | 
				
			||||||
    V: PreorderVisitor<'a> + ?Sized,
 | 
					    V: PreorderVisitor<'a> + ?Sized,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    match module {
 | 
					    match module {
 | 
				
			||||||
        Mod::Module(ModModule {
 | 
					        Mod::Module(ast::ModModule {
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            range: _,
 | 
					            range: _,
 | 
				
			||||||
            type_ignores,
 | 
					            type_ignores,
 | 
				
			||||||
| 
						 | 
					@ -110,9 +114,9 @@ where
 | 
				
			||||||
                visitor.visit_type_ignore(ignore);
 | 
					                visitor.visit_type_ignore(ignore);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Mod::Interactive(ModInteractive { body, range: _ }) => visitor.visit_body(body),
 | 
					        Mod::Interactive(ast::ModInteractive { body, range: _ }) => visitor.visit_body(body),
 | 
				
			||||||
        Mod::Expression(ModExpression { body, range: _ }) => visitor.visit_expr(body),
 | 
					        Mod::Expression(ast::ModExpression { body, range: _ }) => visitor.visit_expr(body),
 | 
				
			||||||
        Mod::FunctionType(ModFunctionType {
 | 
					        Mod::FunctionType(ast::ModFunctionType {
 | 
				
			||||||
            range: _,
 | 
					            range: _,
 | 
				
			||||||
            argtypes,
 | 
					            argtypes,
 | 
				
			||||||
            returns,
 | 
					            returns,
 | 
				
			||||||
| 
						 | 
					@ -140,19 +144,19 @@ where
 | 
				
			||||||
    V: PreorderVisitor<'a> + ?Sized,
 | 
					    V: PreorderVisitor<'a> + ?Sized,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    match stmt {
 | 
					    match stmt {
 | 
				
			||||||
        Stmt::Expr(StmtExpr {
 | 
					        Stmt::Expr(ast::StmtExpr {
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        }) => visitor.visit_expr(value),
 | 
					        }) => visitor.visit_expr(value),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::FunctionDef(StmtFunctionDef {
 | 
					        Stmt::FunctionDef(ast::StmtFunctionDef {
 | 
				
			||||||
            args,
 | 
					            args,
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            decorator_list,
 | 
					            decorator_list,
 | 
				
			||||||
            returns,
 | 
					            returns,
 | 
				
			||||||
            ..
 | 
					            ..
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        | Stmt::AsyncFunctionDef(StmtAsyncFunctionDef {
 | 
					        | Stmt::AsyncFunctionDef(ast::StmtAsyncFunctionDef {
 | 
				
			||||||
            args,
 | 
					            args,
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            decorator_list,
 | 
					            decorator_list,
 | 
				
			||||||
| 
						 | 
					@ -172,7 +176,7 @@ where
 | 
				
			||||||
            visitor.visit_body(body);
 | 
					            visitor.visit_body(body);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::ClassDef(StmtClassDef {
 | 
					        Stmt::ClassDef(ast::StmtClassDef {
 | 
				
			||||||
            bases,
 | 
					            bases,
 | 
				
			||||||
            keywords,
 | 
					            keywords,
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
| 
						 | 
					@ -194,7 +198,7 @@ where
 | 
				
			||||||
            visitor.visit_body(body);
 | 
					            visitor.visit_body(body);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::Return(StmtReturn {
 | 
					        Stmt::Return(ast::StmtReturn {
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        }) => {
 | 
					        }) => {
 | 
				
			||||||
| 
						 | 
					@ -203,7 +207,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::Delete(StmtDelete {
 | 
					        Stmt::Delete(ast::StmtDelete {
 | 
				
			||||||
            targets,
 | 
					            targets,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        }) => {
 | 
					        }) => {
 | 
				
			||||||
| 
						 | 
					@ -212,7 +216,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::Assign(StmtAssign {
 | 
					        Stmt::Assign(ast::StmtAssign {
 | 
				
			||||||
            targets,
 | 
					            targets,
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            range: _,
 | 
					            range: _,
 | 
				
			||||||
| 
						 | 
					@ -225,7 +229,7 @@ where
 | 
				
			||||||
            visitor.visit_expr(value);
 | 
					            visitor.visit_expr(value);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::AugAssign(StmtAugAssign {
 | 
					        Stmt::AugAssign(ast::StmtAugAssign {
 | 
				
			||||||
            target,
 | 
					            target,
 | 
				
			||||||
            op,
 | 
					            op,
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
| 
						 | 
					@ -236,7 +240,7 @@ where
 | 
				
			||||||
            visitor.visit_expr(value);
 | 
					            visitor.visit_expr(value);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::AnnAssign(StmtAnnAssign {
 | 
					        Stmt::AnnAssign(ast::StmtAnnAssign {
 | 
				
			||||||
            target,
 | 
					            target,
 | 
				
			||||||
            annotation,
 | 
					            annotation,
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
| 
						 | 
					@ -250,14 +254,14 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::For(StmtFor {
 | 
					        Stmt::For(ast::StmtFor {
 | 
				
			||||||
            target,
 | 
					            target,
 | 
				
			||||||
            iter,
 | 
					            iter,
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            orelse,
 | 
					            orelse,
 | 
				
			||||||
            ..
 | 
					            ..
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        | Stmt::AsyncFor(StmtAsyncFor {
 | 
					        | Stmt::AsyncFor(ast::StmtAsyncFor {
 | 
				
			||||||
            target,
 | 
					            target,
 | 
				
			||||||
            iter,
 | 
					            iter,
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
| 
						 | 
					@ -270,7 +274,7 @@ where
 | 
				
			||||||
            visitor.visit_body(orelse);
 | 
					            visitor.visit_body(orelse);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::While(StmtWhile {
 | 
					        Stmt::While(ast::StmtWhile {
 | 
				
			||||||
            test,
 | 
					            test,
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            orelse,
 | 
					            orelse,
 | 
				
			||||||
| 
						 | 
					@ -281,7 +285,7 @@ where
 | 
				
			||||||
            visitor.visit_body(orelse);
 | 
					            visitor.visit_body(orelse);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::If(StmtIf {
 | 
					        Stmt::If(ast::StmtIf {
 | 
				
			||||||
            test,
 | 
					            test,
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            orelse,
 | 
					            orelse,
 | 
				
			||||||
| 
						 | 
					@ -292,13 +296,13 @@ where
 | 
				
			||||||
            visitor.visit_body(orelse);
 | 
					            visitor.visit_body(orelse);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::With(StmtWith {
 | 
					        Stmt::With(ast::StmtWith {
 | 
				
			||||||
            items,
 | 
					            items,
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            type_comment: _,
 | 
					            type_comment: _,
 | 
				
			||||||
            range: _,
 | 
					            range: _,
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        | Stmt::AsyncWith(StmtAsyncWith {
 | 
					        | Stmt::AsyncWith(ast::StmtAsyncWith {
 | 
				
			||||||
            items,
 | 
					            items,
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            type_comment: _,
 | 
					            type_comment: _,
 | 
				
			||||||
| 
						 | 
					@ -310,7 +314,7 @@ where
 | 
				
			||||||
            visitor.visit_body(body);
 | 
					            visitor.visit_body(body);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::Match(StmtMatch {
 | 
					        Stmt::Match(ast::StmtMatch {
 | 
				
			||||||
            subject,
 | 
					            subject,
 | 
				
			||||||
            cases,
 | 
					            cases,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -321,7 +325,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::Raise(StmtRaise {
 | 
					        Stmt::Raise(ast::StmtRaise {
 | 
				
			||||||
            exc,
 | 
					            exc,
 | 
				
			||||||
            cause,
 | 
					            cause,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -334,14 +338,14 @@ where
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::Try(StmtTry {
 | 
					        Stmt::Try(ast::StmtTry {
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            handlers,
 | 
					            handlers,
 | 
				
			||||||
            orelse,
 | 
					            orelse,
 | 
				
			||||||
            finalbody,
 | 
					            finalbody,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        | Stmt::TryStar(StmtTryStar {
 | 
					        | Stmt::TryStar(ast::StmtTryStar {
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            handlers,
 | 
					            handlers,
 | 
				
			||||||
            orelse,
 | 
					            orelse,
 | 
				
			||||||
| 
						 | 
					@ -356,7 +360,7 @@ where
 | 
				
			||||||
            visitor.visit_body(finalbody);
 | 
					            visitor.visit_body(finalbody);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::Assert(StmtAssert {
 | 
					        Stmt::Assert(ast::StmtAssert {
 | 
				
			||||||
            test,
 | 
					            test,
 | 
				
			||||||
            msg,
 | 
					            msg,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -367,7 +371,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::Import(StmtImport {
 | 
					        Stmt::Import(ast::StmtImport {
 | 
				
			||||||
            names,
 | 
					            names,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        }) => {
 | 
					        }) => {
 | 
				
			||||||
| 
						 | 
					@ -376,7 +380,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stmt::ImportFrom(StmtImportFrom {
 | 
					        Stmt::ImportFrom(ast::StmtImportFrom {
 | 
				
			||||||
            range: _,
 | 
					            range: _,
 | 
				
			||||||
            module: _,
 | 
					            module: _,
 | 
				
			||||||
            names,
 | 
					            names,
 | 
				
			||||||
| 
						 | 
					@ -411,7 +415,7 @@ where
 | 
				
			||||||
    V: PreorderVisitor<'a> + ?Sized,
 | 
					    V: PreorderVisitor<'a> + ?Sized,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    match expr {
 | 
					    match expr {
 | 
				
			||||||
        Expr::BoolOp(ExprBoolOp {
 | 
					        Expr::BoolOp(ast::ExprBoolOp {
 | 
				
			||||||
            op,
 | 
					            op,
 | 
				
			||||||
            values,
 | 
					            values,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -428,7 +432,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::NamedExpr(ExprNamedExpr {
 | 
					        Expr::NamedExpr(ast::ExprNamedExpr {
 | 
				
			||||||
            target,
 | 
					            target,
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -437,7 +441,7 @@ where
 | 
				
			||||||
            visitor.visit_expr(value);
 | 
					            visitor.visit_expr(value);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::BinOp(ExprBinOp {
 | 
					        Expr::BinOp(ast::ExprBinOp {
 | 
				
			||||||
            left,
 | 
					            left,
 | 
				
			||||||
            op,
 | 
					            op,
 | 
				
			||||||
            right,
 | 
					            right,
 | 
				
			||||||
| 
						 | 
					@ -448,7 +452,7 @@ where
 | 
				
			||||||
            visitor.visit_expr(right);
 | 
					            visitor.visit_expr(right);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::UnaryOp(ExprUnaryOp {
 | 
					        Expr::UnaryOp(ast::ExprUnaryOp {
 | 
				
			||||||
            op,
 | 
					            op,
 | 
				
			||||||
            operand,
 | 
					            operand,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -457,7 +461,7 @@ where
 | 
				
			||||||
            visitor.visit_expr(operand);
 | 
					            visitor.visit_expr(operand);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::Lambda(ExprLambda {
 | 
					        Expr::Lambda(ast::ExprLambda {
 | 
				
			||||||
            args,
 | 
					            args,
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -466,7 +470,7 @@ where
 | 
				
			||||||
            visitor.visit_expr(body);
 | 
					            visitor.visit_expr(body);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::IfExp(ExprIfExp {
 | 
					        Expr::IfExp(ast::ExprIfExp {
 | 
				
			||||||
            test,
 | 
					            test,
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            orelse,
 | 
					            orelse,
 | 
				
			||||||
| 
						 | 
					@ -477,7 +481,7 @@ where
 | 
				
			||||||
            visitor.visit_expr(orelse);
 | 
					            visitor.visit_expr(orelse);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::Dict(ExprDict {
 | 
					        Expr::Dict(ast::ExprDict {
 | 
				
			||||||
            keys,
 | 
					            keys,
 | 
				
			||||||
            values,
 | 
					            values,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -490,7 +494,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::Set(ExprSet {
 | 
					        Expr::Set(ast::ExprSet {
 | 
				
			||||||
            elts,
 | 
					            elts,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        }) => {
 | 
					        }) => {
 | 
				
			||||||
| 
						 | 
					@ -499,7 +503,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::ListComp(ExprListComp {
 | 
					        Expr::ListComp(ast::ExprListComp {
 | 
				
			||||||
            elt,
 | 
					            elt,
 | 
				
			||||||
            generators,
 | 
					            generators,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -510,7 +514,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::SetComp(ExprSetComp {
 | 
					        Expr::SetComp(ast::ExprSetComp {
 | 
				
			||||||
            elt,
 | 
					            elt,
 | 
				
			||||||
            generators,
 | 
					            generators,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -521,7 +525,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::DictComp(ExprDictComp {
 | 
					        Expr::DictComp(ast::ExprDictComp {
 | 
				
			||||||
            key,
 | 
					            key,
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            generators,
 | 
					            generators,
 | 
				
			||||||
| 
						 | 
					@ -535,7 +539,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::GeneratorExp(ExprGeneratorExp {
 | 
					        Expr::GeneratorExp(ast::ExprGeneratorExp {
 | 
				
			||||||
            elt,
 | 
					            elt,
 | 
				
			||||||
            generators,
 | 
					            generators,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -546,16 +550,16 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::Await(ExprAwait {
 | 
					        Expr::Await(ast::ExprAwait {
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        | Expr::YieldFrom(ExprYieldFrom {
 | 
					        | Expr::YieldFrom(ast::ExprYieldFrom {
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        }) => visitor.visit_expr(value),
 | 
					        }) => visitor.visit_expr(value),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::Yield(ExprYield {
 | 
					        Expr::Yield(ast::ExprYield {
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        }) => {
 | 
					        }) => {
 | 
				
			||||||
| 
						 | 
					@ -564,7 +568,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::Compare(ExprCompare {
 | 
					        Expr::Compare(ast::ExprCompare {
 | 
				
			||||||
            left,
 | 
					            left,
 | 
				
			||||||
            ops,
 | 
					            ops,
 | 
				
			||||||
            comparators,
 | 
					            comparators,
 | 
				
			||||||
| 
						 | 
					@ -578,7 +582,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::Call(ExprCall {
 | 
					        Expr::Call(ast::ExprCall {
 | 
				
			||||||
            func,
 | 
					            func,
 | 
				
			||||||
            args,
 | 
					            args,
 | 
				
			||||||
            keywords,
 | 
					            keywords,
 | 
				
			||||||
| 
						 | 
					@ -593,7 +597,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::FormattedValue(ExprFormattedValue {
 | 
					        Expr::FormattedValue(ast::ExprFormattedValue {
 | 
				
			||||||
            value, format_spec, ..
 | 
					            value, format_spec, ..
 | 
				
			||||||
        }) => {
 | 
					        }) => {
 | 
				
			||||||
            visitor.visit_expr(value);
 | 
					            visitor.visit_expr(value);
 | 
				
			||||||
| 
						 | 
					@ -603,7 +607,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::JoinedStr(ExprJoinedStr {
 | 
					        Expr::JoinedStr(ast::ExprJoinedStr {
 | 
				
			||||||
            values,
 | 
					            values,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        }) => {
 | 
					        }) => {
 | 
				
			||||||
| 
						 | 
					@ -612,13 +616,13 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::Constant(ExprConstant {
 | 
					        Expr::Constant(ast::ExprConstant {
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            range: _,
 | 
					            range: _,
 | 
				
			||||||
            kind: _,
 | 
					            kind: _,
 | 
				
			||||||
        }) => visitor.visit_constant(value),
 | 
					        }) => visitor.visit_constant(value),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::Attribute(ExprAttribute {
 | 
					        Expr::Attribute(ast::ExprAttribute {
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            attr: _,
 | 
					            attr: _,
 | 
				
			||||||
            ctx: _,
 | 
					            ctx: _,
 | 
				
			||||||
| 
						 | 
					@ -627,7 +631,7 @@ where
 | 
				
			||||||
            visitor.visit_expr(value);
 | 
					            visitor.visit_expr(value);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::Subscript(ExprSubscript {
 | 
					        Expr::Subscript(ast::ExprSubscript {
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            slice,
 | 
					            slice,
 | 
				
			||||||
            ctx: _,
 | 
					            ctx: _,
 | 
				
			||||||
| 
						 | 
					@ -636,7 +640,7 @@ where
 | 
				
			||||||
            visitor.visit_expr(value);
 | 
					            visitor.visit_expr(value);
 | 
				
			||||||
            visitor.visit_expr(slice);
 | 
					            visitor.visit_expr(slice);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Expr::Starred(ExprStarred {
 | 
					        Expr::Starred(ast::ExprStarred {
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            ctx: _,
 | 
					            ctx: _,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -644,13 +648,13 @@ where
 | 
				
			||||||
            visitor.visit_expr(value);
 | 
					            visitor.visit_expr(value);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::Name(ExprName {
 | 
					        Expr::Name(ast::ExprName {
 | 
				
			||||||
            id: _,
 | 
					            id: _,
 | 
				
			||||||
            ctx: _,
 | 
					            ctx: _,
 | 
				
			||||||
            range: _,
 | 
					            range: _,
 | 
				
			||||||
        }) => {}
 | 
					        }) => {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::List(ExprList {
 | 
					        Expr::List(ast::ExprList {
 | 
				
			||||||
            elts,
 | 
					            elts,
 | 
				
			||||||
            ctx: _,
 | 
					            ctx: _,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -659,7 +663,7 @@ where
 | 
				
			||||||
                visitor.visit_expr(expr);
 | 
					                visitor.visit_expr(expr);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Expr::Tuple(ExprTuple {
 | 
					        Expr::Tuple(ast::ExprTuple {
 | 
				
			||||||
            elts,
 | 
					            elts,
 | 
				
			||||||
            ctx: _,
 | 
					            ctx: _,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
| 
						 | 
					@ -669,7 +673,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Expr::Slice(ExprSlice {
 | 
					        Expr::Slice(ast::ExprSlice {
 | 
				
			||||||
            lower,
 | 
					            lower,
 | 
				
			||||||
            upper,
 | 
					            upper,
 | 
				
			||||||
            step,
 | 
					            step,
 | 
				
			||||||
| 
						 | 
					@ -716,7 +720,7 @@ where
 | 
				
			||||||
    V: PreorderVisitor<'a> + ?Sized,
 | 
					    V: PreorderVisitor<'a> + ?Sized,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    match except_handler {
 | 
					    match except_handler {
 | 
				
			||||||
        ExceptHandler::ExceptHandler(ExceptHandlerExceptHandler {
 | 
					        ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler {
 | 
				
			||||||
            range: _,
 | 
					            range: _,
 | 
				
			||||||
            type_,
 | 
					            type_,
 | 
				
			||||||
            name: _,
 | 
					            name: _,
 | 
				
			||||||
| 
						 | 
					@ -812,19 +816,19 @@ where
 | 
				
			||||||
    V: PreorderVisitor<'a> + ?Sized,
 | 
					    V: PreorderVisitor<'a> + ?Sized,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    match pattern {
 | 
					    match pattern {
 | 
				
			||||||
        Pattern::MatchValue(PatternMatchValue {
 | 
					        Pattern::MatchValue(ast::PatternMatchValue {
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        }) => visitor.visit_expr(value),
 | 
					        }) => visitor.visit_expr(value),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Pattern::MatchSingleton(PatternMatchSingleton {
 | 
					        Pattern::MatchSingleton(ast::PatternMatchSingleton {
 | 
				
			||||||
            value,
 | 
					            value,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        }) => {
 | 
					        }) => {
 | 
				
			||||||
            visitor.visit_constant(value);
 | 
					            visitor.visit_constant(value);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Pattern::MatchSequence(PatternMatchSequence {
 | 
					        Pattern::MatchSequence(ast::PatternMatchSequence {
 | 
				
			||||||
            patterns,
 | 
					            patterns,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        }) => {
 | 
					        }) => {
 | 
				
			||||||
| 
						 | 
					@ -833,7 +837,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Pattern::MatchMapping(PatternMatchMapping {
 | 
					        Pattern::MatchMapping(ast::PatternMatchMapping {
 | 
				
			||||||
            keys,
 | 
					            keys,
 | 
				
			||||||
            patterns,
 | 
					            patterns,
 | 
				
			||||||
            range: _,
 | 
					            range: _,
 | 
				
			||||||
| 
						 | 
					@ -845,7 +849,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Pattern::MatchClass(PatternMatchClass {
 | 
					        Pattern::MatchClass(ast::PatternMatchClass {
 | 
				
			||||||
            cls,
 | 
					            cls,
 | 
				
			||||||
            patterns,
 | 
					            patterns,
 | 
				
			||||||
            kwd_attrs: _,
 | 
					            kwd_attrs: _,
 | 
				
			||||||
| 
						 | 
					@ -864,7 +868,7 @@ where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Pattern::MatchStar(_) => {}
 | 
					        Pattern::MatchStar(_) => {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Pattern::MatchAs(PatternMatchAs {
 | 
					        Pattern::MatchAs(ast::PatternMatchAs {
 | 
				
			||||||
            pattern,
 | 
					            pattern,
 | 
				
			||||||
            range: _,
 | 
					            range: _,
 | 
				
			||||||
            name: _,
 | 
					            name: _,
 | 
				
			||||||
| 
						 | 
					@ -874,7 +878,7 @@ where
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Pattern::MatchOr(PatternMatchOr {
 | 
					        Pattern::MatchOr(ast::PatternMatchOr {
 | 
				
			||||||
            patterns,
 | 
					            patterns,
 | 
				
			||||||
            range: _range,
 | 
					            range: _range,
 | 
				
			||||||
        }) => {
 | 
					        }) => {
 | 
				
			||||||
| 
						 | 
					@ -928,18 +932,20 @@ where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(test)]
 | 
					#[cfg(test)]
 | 
				
			||||||
mod tests {
 | 
					mod tests {
 | 
				
			||||||
 | 
					    use std::fmt::{Debug, Write};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    use insta::assert_snapshot;
 | 
				
			||||||
 | 
					    use rustpython_parser::lexer::lex;
 | 
				
			||||||
 | 
					    use rustpython_parser::{parse_tokens, Mode};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    use crate::node::AnyNodeRef;
 | 
					    use crate::node::AnyNodeRef;
 | 
				
			||||||
    use crate::visitor::preorder::{
 | 
					    use crate::visitor::preorder::{
 | 
				
			||||||
        walk_alias, walk_arg, walk_arguments, walk_comprehension, walk_except_handler, walk_expr,
 | 
					        walk_alias, walk_arg, walk_arguments, walk_comprehension, walk_except_handler, walk_expr,
 | 
				
			||||||
        walk_keyword, walk_match_case, walk_module, walk_pattern, walk_stmt, walk_type_ignore,
 | 
					        walk_keyword, walk_match_case, walk_module, walk_pattern, walk_stmt, walk_type_ignore,
 | 
				
			||||||
        walk_with_item, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant,
 | 
					        walk_with_item, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant,
 | 
				
			||||||
        ExceptHandler, Expr, Keyword, MatchCase, Mod, Operator, Pattern, PreorderVisitor, Stmt,
 | 
					        ExceptHandler, Expr, Keyword, MatchCase, Mod, Operator, Pattern, PreorderVisitor, Stmt,
 | 
				
			||||||
        String, TypeIgnore, UnaryOp, WithItem,
 | 
					        TypeIgnore, UnaryOp, WithItem,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    use insta::assert_snapshot;
 | 
					 | 
				
			||||||
    use rustpython_parser::lexer::lex;
 | 
					 | 
				
			||||||
    use rustpython_parser::{parse_tokens, Mode};
 | 
					 | 
				
			||||||
    use std::fmt::{Debug, Write};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[test]
 | 
					    #[test]
 | 
				
			||||||
    fn function_arguments() {
 | 
					    fn function_arguments() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,12 @@
 | 
				
			||||||
 | 
					use std::fmt::{Debug, Formatter, Write};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use itertools::Itertools;
 | 
				
			||||||
 | 
					use rustpython_parser::ast::Ranged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use ruff_formatter::SourceCode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::comments::node_key::NodeRefEqualityKey;
 | 
					use crate::comments::node_key::NodeRefEqualityKey;
 | 
				
			||||||
use crate::comments::{CommentsMap, SourceComment};
 | 
					use crate::comments::{CommentsMap, SourceComment};
 | 
				
			||||||
use itertools::Itertools;
 | 
					 | 
				
			||||||
use ruff_formatter::SourceCode;
 | 
					 | 
				
			||||||
use ruff_python_ast::prelude::*;
 | 
					 | 
				
			||||||
use std::fmt::{Debug, Formatter, Write};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Prints a debug representation of [`SourceComment`] that includes the comment's text
 | 
					/// Prints a debug representation of [`SourceComment`] that includes the comment's text
 | 
				
			||||||
pub(crate) struct DebugComment<'a> {
 | 
					pub(crate) struct DebugComment<'a> {
 | 
				
			||||||
| 
						 | 
					@ -176,14 +179,16 @@ impl Debug for DebugNodeCommentSlice<'_> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(test)]
 | 
					#[cfg(test)]
 | 
				
			||||||
mod tests {
 | 
					mod tests {
 | 
				
			||||||
    use crate::comments::map::MultiMap;
 | 
					 | 
				
			||||||
    use crate::comments::{CommentLinePosition, Comments, CommentsMap, SourceComment};
 | 
					 | 
				
			||||||
    use insta::assert_debug_snapshot;
 | 
					    use insta::assert_debug_snapshot;
 | 
				
			||||||
    use ruff_formatter::SourceCode;
 | 
					 | 
				
			||||||
    use ruff_python_ast::node::AnyNode;
 | 
					 | 
				
			||||||
    use ruff_text_size::{TextRange, TextSize};
 | 
					    use ruff_text_size::{TextRange, TextSize};
 | 
				
			||||||
    use rustpython_parser::ast::{StmtBreak, StmtContinue};
 | 
					    use rustpython_parser::ast::{StmtBreak, StmtContinue};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    use ruff_formatter::SourceCode;
 | 
				
			||||||
 | 
					    use ruff_python_ast::node::AnyNode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    use crate::comments::map::MultiMap;
 | 
				
			||||||
 | 
					    use crate::comments::{CommentLinePosition, Comments, CommentsMap, SourceComment};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[test]
 | 
					    #[test]
 | 
				
			||||||
    fn debug() {
 | 
					    fn debug() {
 | 
				
			||||||
        let continue_statement = AnyNode::from(StmtContinue {
 | 
					        let continue_statement = AnyNode::from(StmtContinue {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,12 +1,13 @@
 | 
				
			||||||
 | 
					use ruff_text_size::{TextLen, TextRange, TextSize};
 | 
				
			||||||
 | 
					use rustpython_parser::ast::Ranged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use ruff_formatter::{format_args, write, FormatError, SourceCode};
 | 
				
			||||||
 | 
					use ruff_python_ast::node::{AnyNodeRef, AstNode};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::comments::SourceComment;
 | 
					use crate::comments::SourceComment;
 | 
				
			||||||
use crate::context::NodeLevel;
 | 
					use crate::context::NodeLevel;
 | 
				
			||||||
use crate::prelude::*;
 | 
					use crate::prelude::*;
 | 
				
			||||||
use crate::trivia::{lines_after, lines_before, skip_trailing_trivia};
 | 
					use crate::trivia::{lines_after, lines_before, skip_trailing_trivia};
 | 
				
			||||||
use ruff_formatter::{format_args, write, FormatError, SourceCode};
 | 
					 | 
				
			||||||
use ruff_python_ast::node::AnyNodeRef;
 | 
					 | 
				
			||||||
use ruff_python_ast::prelude::AstNode;
 | 
					 | 
				
			||||||
use ruff_text_size::{TextLen, TextRange, TextSize};
 | 
					 | 
				
			||||||
use rustpython_parser::ast::Ranged;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Formats the leading comments of a node.
 | 
					/// Formats the leading comments of a node.
 | 
				
			||||||
pub(crate) fn leading_node_comments<T>(node: &T) -> FormatLeadingComments
 | 
					pub(crate) fn leading_node_comments<T>(node: &T) -> FormatLeadingComments
 | 
				
			||||||
| 
						 | 
					@ -69,7 +70,7 @@ where
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    FormatLeadingAlternateBranchComments {
 | 
					    FormatLeadingAlternateBranchComments {
 | 
				
			||||||
        comments,
 | 
					        comments,
 | 
				
			||||||
        last_node: last_node.map(std::convert::Into::into),
 | 
					        last_node: last_node.map(Into::into),
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -87,10 +87,12 @@
 | 
				
			||||||
//!
 | 
					//!
 | 
				
			||||||
//! It is possible to add an additional optional label to [`SourceComment`] If ever the need arises to distinguish two *dangling comments* in the formatting logic,
 | 
					//! It is possible to add an additional optional label to [`SourceComment`] If ever the need arises to distinguish two *dangling comments* in the formatting logic,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::comments::debug::{DebugComment, DebugComments};
 | 
					use std::cell::Cell;
 | 
				
			||||||
use crate::comments::map::MultiMap;
 | 
					use std::fmt::Debug;
 | 
				
			||||||
use crate::comments::node_key::NodeRefEqualityKey;
 | 
					use std::rc::Rc;
 | 
				
			||||||
use crate::comments::visitor::CommentsVisitor;
 | 
					
 | 
				
			||||||
 | 
					use rustpython_parser::ast::Mod;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub(crate) use format::{
 | 
					pub(crate) use format::{
 | 
				
			||||||
    dangling_comments, dangling_node_comments, leading_alternate_branch_comments, leading_comments,
 | 
					    dangling_comments, dangling_node_comments, leading_alternate_branch_comments, leading_comments,
 | 
				
			||||||
    leading_node_comments, trailing_comments, trailing_node_comments,
 | 
					    leading_node_comments, trailing_comments, trailing_node_comments,
 | 
				
			||||||
| 
						 | 
					@ -98,10 +100,11 @@ pub(crate) use format::{
 | 
				
			||||||
use ruff_formatter::{SourceCode, SourceCodeSlice};
 | 
					use ruff_formatter::{SourceCode, SourceCodeSlice};
 | 
				
			||||||
use ruff_python_ast::node::AnyNodeRef;
 | 
					use ruff_python_ast::node::AnyNodeRef;
 | 
				
			||||||
use ruff_python_ast::source_code::CommentRanges;
 | 
					use ruff_python_ast::source_code::CommentRanges;
 | 
				
			||||||
use rustpython_parser::ast::Mod;
 | 
					
 | 
				
			||||||
use std::cell::Cell;
 | 
					use crate::comments::debug::{DebugComment, DebugComments};
 | 
				
			||||||
use std::fmt::Debug;
 | 
					use crate::comments::map::MultiMap;
 | 
				
			||||||
use std::rc::Rc;
 | 
					use crate::comments::node_key::NodeRefEqualityKey;
 | 
				
			||||||
 | 
					use crate::comments::visitor::CommentsVisitor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mod debug;
 | 
					mod debug;
 | 
				
			||||||
mod format;
 | 
					mod format;
 | 
				
			||||||
| 
						 | 
					@ -404,14 +407,16 @@ struct CommentsData<'a> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(test)]
 | 
					#[cfg(test)]
 | 
				
			||||||
mod tests {
 | 
					mod tests {
 | 
				
			||||||
    use crate::comments::Comments;
 | 
					 | 
				
			||||||
    use insta::assert_debug_snapshot;
 | 
					    use insta::assert_debug_snapshot;
 | 
				
			||||||
    use ruff_formatter::SourceCode;
 | 
					    use rustpython_parser::ast::Mod;
 | 
				
			||||||
    use ruff_python_ast::prelude::*;
 | 
					 | 
				
			||||||
    use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder};
 | 
					 | 
				
			||||||
    use rustpython_parser::lexer::lex;
 | 
					    use rustpython_parser::lexer::lex;
 | 
				
			||||||
    use rustpython_parser::{parse_tokens, Mode};
 | 
					    use rustpython_parser::{parse_tokens, Mode};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    use ruff_formatter::SourceCode;
 | 
				
			||||||
 | 
					    use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    use crate::comments::Comments;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    struct CommentsTestCase<'a> {
 | 
					    struct CommentsTestCase<'a> {
 | 
				
			||||||
        module: Mod,
 | 
					        module: Mod,
 | 
				
			||||||
        comment_ranges: CommentRanges,
 | 
					        comment_ranges: CommentRanges,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,16 +1,20 @@
 | 
				
			||||||
 | 
					use std::cmp::Ordering;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use ruff_text_size::TextRange;
 | 
				
			||||||
 | 
					use rustpython_parser::ast;
 | 
				
			||||||
 | 
					use rustpython_parser::ast::{Expr, ExprSlice, Ranged};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use ruff_python_ast::node::{AnyNodeRef, AstNode};
 | 
				
			||||||
 | 
					use ruff_python_ast::source_code::Locator;
 | 
				
			||||||
 | 
					use ruff_python_ast::whitespace;
 | 
				
			||||||
 | 
					use ruff_python_whitespace::{PythonWhitespace, UniversalNewlines};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::comments::visitor::{CommentPlacement, DecoratedComment};
 | 
					use crate::comments::visitor::{CommentPlacement, DecoratedComment};
 | 
				
			||||||
use crate::expression::expr_slice::{assign_comment_in_slice, ExprSliceCommentSection};
 | 
					use crate::expression::expr_slice::{assign_comment_in_slice, ExprSliceCommentSection};
 | 
				
			||||||
use crate::other::arguments::{
 | 
					use crate::other::arguments::{
 | 
				
			||||||
    assign_argument_separator_comment_placement, find_argument_separators,
 | 
					    assign_argument_separator_comment_placement, find_argument_separators,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use crate::trivia::{first_non_trivia_token_rev, SimpleTokenizer, Token, TokenKind};
 | 
					use crate::trivia::{first_non_trivia_token_rev, SimpleTokenizer, Token, TokenKind};
 | 
				
			||||||
use ruff_python_ast::node::{AnyNodeRef, AstNode};
 | 
					 | 
				
			||||||
use ruff_python_ast::source_code::Locator;
 | 
					 | 
				
			||||||
use ruff_python_ast::whitespace;
 | 
					 | 
				
			||||||
use ruff_python_whitespace::{PythonWhitespace, UniversalNewlines};
 | 
					 | 
				
			||||||
use ruff_text_size::TextRange;
 | 
					 | 
				
			||||||
use rustpython_parser::ast::{Expr, ExprSlice, Ranged};
 | 
					 | 
				
			||||||
use std::cmp::Ordering;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Implements the custom comment placement logic.
 | 
					/// Implements the custom comment placement logic.
 | 
				
			||||||
pub(super) fn place_comment<'a>(
 | 
					pub(super) fn place_comment<'a>(
 | 
				
			||||||
| 
						 | 
					@ -574,8 +578,6 @@ fn handle_trailing_end_of_line_condition_comment<'a>(
 | 
				
			||||||
    comment: DecoratedComment<'a>,
 | 
					    comment: DecoratedComment<'a>,
 | 
				
			||||||
    locator: &Locator,
 | 
					    locator: &Locator,
 | 
				
			||||||
) -> CommentPlacement<'a> {
 | 
					) -> CommentPlacement<'a> {
 | 
				
			||||||
    use ruff_python_ast::prelude::*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Must be an end of line comment
 | 
					    // Must be an end of line comment
 | 
				
			||||||
    if comment.line_position().is_own_line() {
 | 
					    if comment.line_position().is_own_line() {
 | 
				
			||||||
        return CommentPlacement::Default(comment);
 | 
					        return CommentPlacement::Default(comment);
 | 
				
			||||||
| 
						 | 
					@ -587,23 +589,25 @@ fn handle_trailing_end_of_line_condition_comment<'a>(
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let expression_before_colon = match comment.enclosing_node() {
 | 
					    let expression_before_colon = match comment.enclosing_node() {
 | 
				
			||||||
        AnyNodeRef::StmtIf(StmtIf { test: expr, .. })
 | 
					        AnyNodeRef::StmtIf(ast::StmtIf { test: expr, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtWhile(StmtWhile { test: expr, .. })
 | 
					        | AnyNodeRef::StmtWhile(ast::StmtWhile { test: expr, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtFor(StmtFor { iter: expr, .. })
 | 
					        | AnyNodeRef::StmtFor(ast::StmtFor { iter: expr, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtAsyncFor(StmtAsyncFor { iter: expr, .. }) => {
 | 
					        | AnyNodeRef::StmtAsyncFor(ast::StmtAsyncFor { iter: expr, .. }) => {
 | 
				
			||||||
            Some(AnyNodeRef::from(expr.as_ref()))
 | 
					            Some(AnyNodeRef::from(expr.as_ref()))
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        AnyNodeRef::StmtWith(StmtWith { items, .. })
 | 
					        AnyNodeRef::StmtWith(ast::StmtWith { items, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtAsyncWith(StmtAsyncWith { items, .. }) => {
 | 
					        | AnyNodeRef::StmtAsyncWith(ast::StmtAsyncWith { items, .. }) => {
 | 
				
			||||||
            items.last().map(AnyNodeRef::from)
 | 
					            items.last().map(AnyNodeRef::from)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        AnyNodeRef::StmtFunctionDef(StmtFunctionDef { returns, args, .. })
 | 
					        AnyNodeRef::StmtFunctionDef(ast::StmtFunctionDef { returns, args, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtAsyncFunctionDef(StmtAsyncFunctionDef { returns, args, .. }) => returns
 | 
					        | AnyNodeRef::StmtAsyncFunctionDef(ast::StmtAsyncFunctionDef { returns, args, .. }) => {
 | 
				
			||||||
 | 
					            returns
 | 
				
			||||||
                .as_deref()
 | 
					                .as_deref()
 | 
				
			||||||
                .map(AnyNodeRef::from)
 | 
					                .map(AnyNodeRef::from)
 | 
				
			||||||
            .or_else(|| Some(AnyNodeRef::from(args.as_ref()))),
 | 
					                .or_else(|| Some(AnyNodeRef::from(args.as_ref())))
 | 
				
			||||||
        AnyNodeRef::StmtClassDef(StmtClassDef {
 | 
					        }
 | 
				
			||||||
 | 
					        AnyNodeRef::StmtClassDef(ast::StmtClassDef {
 | 
				
			||||||
            bases, keywords, ..
 | 
					            bases, keywords, ..
 | 
				
			||||||
        }) => keywords
 | 
					        }) => keywords
 | 
				
			||||||
            .last()
 | 
					            .last()
 | 
				
			||||||
| 
						 | 
					@ -1104,21 +1108,21 @@ where
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn last_child_in_body(node: AnyNodeRef) -> Option<AnyNodeRef> {
 | 
					fn last_child_in_body(node: AnyNodeRef) -> Option<AnyNodeRef> {
 | 
				
			||||||
    use ruff_python_ast::prelude::*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let body = match node {
 | 
					    let body = match node {
 | 
				
			||||||
        AnyNodeRef::StmtFunctionDef(StmtFunctionDef { body, .. })
 | 
					        AnyNodeRef::StmtFunctionDef(ast::StmtFunctionDef { body, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtAsyncFunctionDef(StmtAsyncFunctionDef { body, .. })
 | 
					        | AnyNodeRef::StmtAsyncFunctionDef(ast::StmtAsyncFunctionDef { body, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtClassDef(StmtClassDef { body, .. })
 | 
					        | AnyNodeRef::StmtClassDef(ast::StmtClassDef { body, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtWith(StmtWith { body, .. })
 | 
					        | AnyNodeRef::StmtWith(ast::StmtWith { body, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtAsyncWith(StmtAsyncWith { body, .. })
 | 
					        | AnyNodeRef::StmtAsyncWith(ast::StmtAsyncWith { body, .. })
 | 
				
			||||||
        | AnyNodeRef::MatchCase(MatchCase { body, .. })
 | 
					        | AnyNodeRef::MatchCase(ast::MatchCase { body, .. })
 | 
				
			||||||
        | AnyNodeRef::ExceptHandlerExceptHandler(ExceptHandlerExceptHandler { body, .. }) => body,
 | 
					        | AnyNodeRef::ExceptHandlerExceptHandler(ast::ExceptHandlerExceptHandler {
 | 
				
			||||||
 | 
					            body, ..
 | 
				
			||||||
 | 
					        }) => body,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        AnyNodeRef::StmtIf(StmtIf { body, orelse, .. })
 | 
					        AnyNodeRef::StmtIf(ast::StmtIf { body, orelse, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtFor(StmtFor { body, orelse, .. })
 | 
					        | AnyNodeRef::StmtFor(ast::StmtFor { body, orelse, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtAsyncFor(StmtAsyncFor { body, orelse, .. })
 | 
					        | AnyNodeRef::StmtAsyncFor(ast::StmtAsyncFor { body, orelse, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtWhile(StmtWhile { body, orelse, .. }) => {
 | 
					        | AnyNodeRef::StmtWhile(ast::StmtWhile { body, orelse, .. }) => {
 | 
				
			||||||
            if orelse.is_empty() {
 | 
					            if orelse.is_empty() {
 | 
				
			||||||
                body
 | 
					                body
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
| 
						 | 
					@ -1126,18 +1130,18 @@ fn last_child_in_body(node: AnyNodeRef) -> Option<AnyNodeRef> {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        AnyNodeRef::StmtMatch(StmtMatch { cases, .. }) => {
 | 
					        AnyNodeRef::StmtMatch(ast::StmtMatch { cases, .. }) => {
 | 
				
			||||||
            return cases.last().map(AnyNodeRef::from)
 | 
					            return cases.last().map(AnyNodeRef::from)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        AnyNodeRef::StmtTry(StmtTry {
 | 
					        AnyNodeRef::StmtTry(ast::StmtTry {
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            handlers,
 | 
					            handlers,
 | 
				
			||||||
            orelse,
 | 
					            orelse,
 | 
				
			||||||
            finalbody,
 | 
					            finalbody,
 | 
				
			||||||
            ..
 | 
					            ..
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        | AnyNodeRef::StmtTryStar(StmtTryStar {
 | 
					        | AnyNodeRef::StmtTryStar(ast::StmtTryStar {
 | 
				
			||||||
            body,
 | 
					            body,
 | 
				
			||||||
            handlers,
 | 
					            handlers,
 | 
				
			||||||
            orelse,
 | 
					            orelse,
 | 
				
			||||||
| 
						 | 
					@ -1171,23 +1175,21 @@ fn is_first_statement_in_enclosing_alternate_body(
 | 
				
			||||||
    following: AnyNodeRef,
 | 
					    following: AnyNodeRef,
 | 
				
			||||||
    enclosing: AnyNodeRef,
 | 
					    enclosing: AnyNodeRef,
 | 
				
			||||||
) -> bool {
 | 
					) -> bool {
 | 
				
			||||||
    use ruff_python_ast::prelude::*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    match enclosing {
 | 
					    match enclosing {
 | 
				
			||||||
        AnyNodeRef::StmtIf(StmtIf { orelse, .. })
 | 
					        AnyNodeRef::StmtIf(ast::StmtIf { orelse, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtFor(StmtFor { orelse, .. })
 | 
					        | AnyNodeRef::StmtFor(ast::StmtFor { orelse, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtAsyncFor(StmtAsyncFor { orelse, .. })
 | 
					        | AnyNodeRef::StmtAsyncFor(ast::StmtAsyncFor { orelse, .. })
 | 
				
			||||||
        | AnyNodeRef::StmtWhile(StmtWhile { orelse, .. }) => {
 | 
					        | AnyNodeRef::StmtWhile(ast::StmtWhile { orelse, .. }) => {
 | 
				
			||||||
            are_same_optional(following, orelse.first())
 | 
					            are_same_optional(following, orelse.first())
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        AnyNodeRef::StmtTry(StmtTry {
 | 
					        AnyNodeRef::StmtTry(ast::StmtTry {
 | 
				
			||||||
            handlers,
 | 
					            handlers,
 | 
				
			||||||
            orelse,
 | 
					            orelse,
 | 
				
			||||||
            finalbody,
 | 
					            finalbody,
 | 
				
			||||||
            ..
 | 
					            ..
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        | AnyNodeRef::StmtTryStar(StmtTryStar {
 | 
					        | AnyNodeRef::StmtTryStar(ast::StmtTryStar {
 | 
				
			||||||
            handlers,
 | 
					            handlers,
 | 
				
			||||||
            orelse,
 | 
					            orelse,
 | 
				
			||||||
            finalbody,
 | 
					            finalbody,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,17 +1,23 @@
 | 
				
			||||||
use crate::comments::node_key::NodeRefEqualityKey;
 | 
					use std::iter::Peekable;
 | 
				
			||||||
use crate::comments::placement::place_comment;
 | 
					
 | 
				
			||||||
use crate::comments::{CommentLinePosition, CommentsMap, SourceComment};
 | 
					use ruff_text_size::{TextRange, TextSize};
 | 
				
			||||||
 | 
					use rustpython_parser::ast::{
 | 
				
			||||||
 | 
					    Alias, Arg, ArgWithDefault, Arguments, Comprehension, Decorator, ExceptHandler, Expr, Keyword,
 | 
				
			||||||
 | 
					    MatchCase, Mod, Pattern, Ranged, Stmt, WithItem,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ruff_formatter::{SourceCode, SourceCodeSlice};
 | 
					use ruff_formatter::{SourceCode, SourceCodeSlice};
 | 
				
			||||||
use ruff_python_ast::node::AnyNodeRef;
 | 
					use ruff_python_ast::node::AnyNodeRef;
 | 
				
			||||||
use ruff_python_ast::prelude::*;
 | 
					 | 
				
			||||||
use ruff_python_ast::source_code::{CommentRanges, Locator};
 | 
					use ruff_python_ast::source_code::{CommentRanges, Locator};
 | 
				
			||||||
// The interface is designed to only export the members relevant for iterating nodes in
 | 
					// The interface is designed to only export the members relevant for iterating nodes in
 | 
				
			||||||
// pre-order.
 | 
					// pre-order.
 | 
				
			||||||
#[allow(clippy::wildcard_imports)]
 | 
					#[allow(clippy::wildcard_imports)]
 | 
				
			||||||
use ruff_python_ast::visitor::preorder::*;
 | 
					use ruff_python_ast::visitor::preorder::*;
 | 
				
			||||||
use ruff_python_whitespace::is_python_whitespace;
 | 
					use ruff_python_whitespace::is_python_whitespace;
 | 
				
			||||||
use ruff_text_size::TextRange;
 | 
					
 | 
				
			||||||
use std::iter::Peekable;
 | 
					use crate::comments::node_key::NodeRefEqualityKey;
 | 
				
			||||||
 | 
					use crate::comments::placement::place_comment;
 | 
				
			||||||
 | 
					use crate::comments::{CommentLinePosition, CommentsMap, SourceComment};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Visitor extracting the comments from an AST.
 | 
					/// Visitor extracting the comments from an AST.
 | 
				
			||||||
#[derive(Debug, Clone)]
 | 
					#[derive(Debug, Clone)]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,10 +1,12 @@
 | 
				
			||||||
//! This module provides helper utilities to format an expression that has a left side, an operator,
 | 
					//! This module provides helper utilities to format an expression that has a left side, an operator,
 | 
				
			||||||
//! and a right side (binary like).
 | 
					//! and a right side (binary like).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use rustpython_parser::ast::{self, Expr};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use ruff_formatter::{format_args, write};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::expression::parentheses::Parentheses;
 | 
					use crate::expression::parentheses::Parentheses;
 | 
				
			||||||
use crate::prelude::*;
 | 
					use crate::prelude::*;
 | 
				
			||||||
use ruff_formatter::{format_args, write};
 | 
					 | 
				
			||||||
use rustpython_parser::ast::Expr;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Trait to implement a binary like syntax that has a left operand, an operator, and a right operand.
 | 
					/// Trait to implement a binary like syntax that has a left operand, an operator, and a right operand.
 | 
				
			||||||
pub(super) trait FormatBinaryLike<'ast> {
 | 
					pub(super) trait FormatBinaryLike<'ast> {
 | 
				
			||||||
| 
						 | 
					@ -133,25 +135,25 @@ pub(super) trait FormatBinaryLike<'ast> {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn can_break_expr(expr: &Expr) -> bool {
 | 
					fn can_break_expr(expr: &Expr) -> bool {
 | 
				
			||||||
    use ruff_python_ast::prelude::*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    match expr {
 | 
					    match expr {
 | 
				
			||||||
        Expr::Tuple(ExprTuple {
 | 
					        Expr::Tuple(ast::ExprTuple {
 | 
				
			||||||
            elts: expressions, ..
 | 
					            elts: expressions, ..
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        | Expr::List(ExprList {
 | 
					        | Expr::List(ast::ExprList {
 | 
				
			||||||
            elts: expressions, ..
 | 
					            elts: expressions, ..
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        | Expr::Set(ExprSet {
 | 
					        | Expr::Set(ast::ExprSet {
 | 
				
			||||||
            elts: expressions, ..
 | 
					            elts: expressions, ..
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        | Expr::Dict(ExprDict {
 | 
					        | Expr::Dict(ast::ExprDict {
 | 
				
			||||||
            values: expressions,
 | 
					            values: expressions,
 | 
				
			||||||
            ..
 | 
					            ..
 | 
				
			||||||
        }) => !expressions.is_empty(),
 | 
					        }) => !expressions.is_empty(),
 | 
				
			||||||
        Expr::Call(ExprCall { args, keywords, .. }) => !(args.is_empty() && keywords.is_empty()),
 | 
					        Expr::Call(ast::ExprCall { args, keywords, .. }) => {
 | 
				
			||||||
 | 
					            !(args.is_empty() && keywords.is_empty())
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        Expr::ListComp(_) | Expr::SetComp(_) | Expr::DictComp(_) | Expr::GeneratorExp(_) => true,
 | 
					        Expr::ListComp(_) | Expr::SetComp(_) | Expr::DictComp(_) | Expr::GeneratorExp(_) => true,
 | 
				
			||||||
        Expr::UnaryOp(ExprUnaryOp { operand, .. }) => match operand.as_ref() {
 | 
					        Expr::UnaryOp(ast::ExprUnaryOp { operand, .. }) => match operand.as_ref() {
 | 
				
			||||||
            Expr::BinOp(_) => true,
 | 
					            Expr::BinOp(_) => true,
 | 
				
			||||||
            _ => can_break_expr(operand.as_ref()),
 | 
					            _ => can_break_expr(operand.as_ref()),
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,7 @@ use crate::FormatNodeRule;
 | 
				
			||||||
use ruff_formatter::{
 | 
					use ruff_formatter::{
 | 
				
			||||||
    write, FormatError, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions,
 | 
					    write, FormatError, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use ruff_python_ast::prelude::Expr;
 | 
					use rustpython_parser::ast::Expr;
 | 
				
			||||||
use rustpython_parser::ast::{CmpOp, ExprCompare};
 | 
					use rustpython_parser::ast::{CmpOp, ExprCompare};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default)]
 | 
					#[derive(Default)]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,8 +5,8 @@ use crate::expression::parentheses::{
 | 
				
			||||||
use crate::prelude::*;
 | 
					use crate::prelude::*;
 | 
				
			||||||
use crate::FormatNodeRule;
 | 
					use crate::FormatNodeRule;
 | 
				
			||||||
use ruff_formatter::{format_args, write};
 | 
					use ruff_formatter::{format_args, write};
 | 
				
			||||||
use ruff_python_ast::prelude::Ranged;
 | 
					 | 
				
			||||||
use ruff_text_size::TextRange;
 | 
					use ruff_text_size::TextRange;
 | 
				
			||||||
 | 
					use rustpython_parser::ast::Ranged;
 | 
				
			||||||
use rustpython_parser::ast::{Expr, ExprDict};
 | 
					use rustpython_parser::ast::{Expr, ExprDict};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default)]
 | 
					#[derive(Default)]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,9 +8,9 @@ use crate::{AsFormat, FormatNodeRule, PyFormatter};
 | 
				
			||||||
use ruff_formatter::prelude::{hard_line_break, line_suffix_boundary, space, text};
 | 
					use ruff_formatter::prelude::{hard_line_break, line_suffix_boundary, space, text};
 | 
				
			||||||
use ruff_formatter::{write, Buffer, Format, FormatError, FormatResult};
 | 
					use ruff_formatter::{write, Buffer, Format, FormatError, FormatResult};
 | 
				
			||||||
use ruff_python_ast::node::AstNode;
 | 
					use ruff_python_ast::node::AstNode;
 | 
				
			||||||
use ruff_python_ast::prelude::{Expr, Ranged};
 | 
					 | 
				
			||||||
use ruff_text_size::TextRange;
 | 
					use ruff_text_size::TextRange;
 | 
				
			||||||
use rustpython_parser::ast::ExprSlice;
 | 
					use rustpython_parser::ast::ExprSlice;
 | 
				
			||||||
 | 
					use rustpython_parser::ast::{Expr, Ranged};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default)]
 | 
					#[derive(Default)]
 | 
				
			||||||
pub struct FormatExprSlice;
 | 
					pub struct FormatExprSlice;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,9 +5,9 @@ use crate::expression::parentheses::{
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use crate::prelude::*;
 | 
					use crate::prelude::*;
 | 
				
			||||||
use ruff_formatter::{format_args, write, FormatRuleWithOptions};
 | 
					use ruff_formatter::{format_args, write, FormatRuleWithOptions};
 | 
				
			||||||
use ruff_python_ast::prelude::{Expr, Ranged};
 | 
					 | 
				
			||||||
use ruff_text_size::TextRange;
 | 
					use ruff_text_size::TextRange;
 | 
				
			||||||
use rustpython_parser::ast::ExprTuple;
 | 
					use rustpython_parser::ast::ExprTuple;
 | 
				
			||||||
 | 
					use rustpython_parser::ast::{Expr, Ranged};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Eq, PartialEq, Debug, Default)]
 | 
					#[derive(Eq, PartialEq, Debug, Default)]
 | 
				
			||||||
pub enum TupleParentheses {
 | 
					pub enum TupleParentheses {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,8 +6,8 @@ use crate::trivia::{SimpleTokenizer, TokenKind};
 | 
				
			||||||
use crate::{AsFormat, FormatNodeRule, PyFormatter};
 | 
					use crate::{AsFormat, FormatNodeRule, PyFormatter};
 | 
				
			||||||
use ruff_formatter::prelude::{hard_line_break, space, text};
 | 
					use ruff_formatter::prelude::{hard_line_break, space, text};
 | 
				
			||||||
use ruff_formatter::{Format, FormatContext, FormatResult};
 | 
					use ruff_formatter::{Format, FormatContext, FormatResult};
 | 
				
			||||||
use ruff_python_ast::prelude::UnaryOp;
 | 
					 | 
				
			||||||
use ruff_text_size::{TextLen, TextRange};
 | 
					use ruff_text_size::{TextLen, TextRange};
 | 
				
			||||||
 | 
					use rustpython_parser::ast::UnaryOp;
 | 
				
			||||||
use rustpython_parser::ast::{ExprUnaryOp, Ranged};
 | 
					use rustpython_parser::ast::{ExprUnaryOp, Ranged};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default)]
 | 
					#[derive(Default)]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ use crate::{AsFormat, FormatNodeRule, PyFormatter};
 | 
				
			||||||
use ruff_formatter::formatter::Formatter;
 | 
					use ruff_formatter::formatter::Formatter;
 | 
				
			||||||
use ruff_formatter::prelude::{space, text};
 | 
					use ruff_formatter::prelude::{space, text};
 | 
				
			||||||
use ruff_formatter::{write, Buffer, Format, FormatResult};
 | 
					use ruff_formatter::{write, Buffer, Format, FormatResult};
 | 
				
			||||||
use ruff_python_ast::prelude::Expr;
 | 
					use rustpython_parser::ast::Expr;
 | 
				
			||||||
use rustpython_parser::ast::StmtAssign;
 | 
					use rustpython_parser::ast::StmtAssign;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Note: This currently does wrap but not the black way so the types below likely need to be
 | 
					// Note: This currently does wrap but not the black way so the types below likely need to be
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,10 +1,12 @@
 | 
				
			||||||
 | 
					use rustpython_parser::ast::StmtWith;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use ruff_formatter::{write, Buffer, FormatResult};
 | 
				
			||||||
 | 
					use ruff_python_ast::node::AstNode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::builders::optional_parentheses;
 | 
					use crate::builders::optional_parentheses;
 | 
				
			||||||
use crate::comments::trailing_comments;
 | 
					use crate::comments::trailing_comments;
 | 
				
			||||||
use crate::prelude::*;
 | 
					use crate::prelude::*;
 | 
				
			||||||
use crate::{FormatNodeRule, PyFormatter};
 | 
					use crate::{FormatNodeRule, PyFormatter};
 | 
				
			||||||
use ruff_formatter::{write, Buffer, FormatResult};
 | 
					 | 
				
			||||||
use ruff_python_ast::prelude::*;
 | 
					 | 
				
			||||||
use rustpython_parser::ast::StmtWith;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default)]
 | 
					#[derive(Default)]
 | 
				
			||||||
pub struct FormatStmtWith;
 | 
					pub struct FormatStmtWith;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,9 @@ ruff_python_ast = { path = "../crates/ruff_python_ast" }
 | 
				
			||||||
ruff_python_formatter = { path = "../crates/ruff_python_formatter" }
 | 
					ruff_python_formatter = { path = "../crates/ruff_python_formatter" }
 | 
				
			||||||
similar = { version = "2.2.1" }
 | 
					similar = { version = "2.2.1" }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Current tag: v0.0.6
 | 
				
			||||||
 | 
					rustpython-parser = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "8078663b6c914c1cb86993e427764f7c422fc12c" , default-features = false, features = ["full-lexer", "num-bigint"] }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Prevent this from interfering with workspaces
 | 
					# Prevent this from interfering with workspaces
 | 
				
			||||||
[workspace]
 | 
					[workspace]
 | 
				
			||||||
members = ["."]
 | 
					members = ["."]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,8 +4,9 @@
 | 
				
			||||||
#![no_main]
 | 
					#![no_main]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use libfuzzer_sys::{fuzz_target, Corpus};
 | 
					use libfuzzer_sys::{fuzz_target, Corpus};
 | 
				
			||||||
use ruff_python_ast::prelude::{lexer, Mode, Parse, ParseError, Suite};
 | 
					 | 
				
			||||||
use ruff_python_ast::source_code::{Generator, Locator, Stylist};
 | 
					use ruff_python_ast::source_code::{Generator, Locator, Stylist};
 | 
				
			||||||
 | 
					use rustpython_parser::ast::Suite;
 | 
				
			||||||
 | 
					use rustpython_parser::{lexer, Mode, Parse, ParseError};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn do_fuzz(case: &[u8]) -> Corpus {
 | 
					fn do_fuzz(case: &[u8]) -> Corpus {
 | 
				
			||||||
    let Ok(code) = std::str::from_utf8(case) else { return Corpus::Reject; };
 | 
					    let Ok(code) = std::str::from_utf8(case) else { return Corpus::Reject; };
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue