diff --git a/crates/ruff_python_ast/src/node.rs b/crates/ruff_python_ast/src/node.rs index 39392573eb27c..102e04723690f 100644 --- a/crates/ruff_python_ast/src/node.rs +++ b/crates/ruff_python_ast/src/node.rs @@ -1,7 +1,7 @@ use crate::{ self as ast, Alias, Arg, ArgWithDefault, Arguments, Comprehension, Decorator, ExceptHandler, - Expr, Keyword, MatchCase, Mod, Pattern, Ranged, Stmt, TypeIgnore, TypeParam, - TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, WithItem, + Expr, Keyword, MatchCase, Mod, Pattern, Ranged, Stmt, TypeParam, TypeParamParamSpec, + TypeParamTypeVar, TypeParamTypeVarTuple, WithItem, }; use ruff_text_size::TextRange; use std::ptr::NonNull; @@ -91,7 +91,6 @@ pub enum AnyNode { PatternMatchStar(ast::PatternMatchStar), PatternMatchAs(ast::PatternMatchAs), PatternMatchOr(ast::PatternMatchOr), - TypeIgnoreTypeIgnore(ast::TypeIgnoreTypeIgnore), Comprehension(Comprehension), Arguments(Arguments), Arg(Arg), @@ -181,7 +180,6 @@ impl AnyNode { | AnyNode::PatternMatchStar(_) | AnyNode::PatternMatchAs(_) | AnyNode::PatternMatchOr(_) - | AnyNode::TypeIgnoreTypeIgnore(_) | AnyNode::Comprehension(_) | AnyNode::Arguments(_) | AnyNode::Arg(_) @@ -271,7 +269,6 @@ impl AnyNode { | AnyNode::PatternMatchStar(_) | AnyNode::PatternMatchAs(_) | AnyNode::PatternMatchOr(_) - | AnyNode::TypeIgnoreTypeIgnore(_) | AnyNode::Comprehension(_) | AnyNode::Arguments(_) | AnyNode::Arg(_) @@ -361,7 +358,6 @@ impl AnyNode { | AnyNode::PatternMatchStar(_) | AnyNode::PatternMatchAs(_) | AnyNode::PatternMatchOr(_) - | AnyNode::TypeIgnoreTypeIgnore(_) | AnyNode::Comprehension(_) | AnyNode::Arguments(_) | AnyNode::Arg(_) @@ -451,7 +447,6 @@ impl AnyNode { | AnyNode::ExprSlice(_) | AnyNode::ExprLineMagic(_) | AnyNode::ExceptHandlerExceptHandler(_) - | AnyNode::TypeIgnoreTypeIgnore(_) | AnyNode::Comprehension(_) | AnyNode::Arguments(_) | AnyNode::Arg(_) @@ -541,97 +536,6 @@ impl AnyNode { | AnyNode::PatternMatchStar(_) | AnyNode::PatternMatchAs(_) | AnyNode::PatternMatchOr(_) - | AnyNode::TypeIgnoreTypeIgnore(_) - | AnyNode::Comprehension(_) - | AnyNode::Arguments(_) - | AnyNode::Arg(_) - | AnyNode::ArgWithDefault(_) - | AnyNode::Keyword(_) - | AnyNode::Alias(_) - | AnyNode::WithItem(_) - | AnyNode::MatchCase(_) - | AnyNode::Decorator(_) - | AnyNode::TypeParamTypeVar(_) - | AnyNode::TypeParamTypeVarTuple(_) - | AnyNode::TypeParamParamSpec(_) - | AnyNode::ElifElseClause(_) => None, - } - } - - pub fn type_ignore(self) -> Option { - match self { - AnyNode::TypeIgnoreTypeIgnore(node) => Some(TypeIgnore::TypeIgnore(node)), - - AnyNode::ModModule(_) - | AnyNode::ModInteractive(_) - | AnyNode::ModExpression(_) - | AnyNode::ModFunctionType(_) - | AnyNode::StmtFunctionDef(_) - | AnyNode::StmtAsyncFunctionDef(_) - | AnyNode::StmtClassDef(_) - | AnyNode::StmtReturn(_) - | AnyNode::StmtDelete(_) - | AnyNode::StmtTypeAlias(_) - | AnyNode::StmtAssign(_) - | AnyNode::StmtAugAssign(_) - | AnyNode::StmtAnnAssign(_) - | AnyNode::StmtFor(_) - | AnyNode::StmtAsyncFor(_) - | AnyNode::StmtWhile(_) - | AnyNode::StmtIf(_) - | AnyNode::StmtWith(_) - | AnyNode::StmtAsyncWith(_) - | AnyNode::StmtMatch(_) - | AnyNode::StmtRaise(_) - | AnyNode::StmtTry(_) - | AnyNode::StmtTryStar(_) - | AnyNode::StmtAssert(_) - | AnyNode::StmtImport(_) - | AnyNode::StmtImportFrom(_) - | AnyNode::StmtGlobal(_) - | AnyNode::StmtNonlocal(_) - | AnyNode::StmtExpr(_) - | AnyNode::StmtPass(_) - | AnyNode::StmtBreak(_) - | AnyNode::StmtContinue(_) - | AnyNode::StmtLineMagic(_) - | AnyNode::ExprBoolOp(_) - | AnyNode::ExprNamedExpr(_) - | AnyNode::ExprBinOp(_) - | AnyNode::ExprUnaryOp(_) - | AnyNode::ExprLambda(_) - | AnyNode::ExprIfExp(_) - | AnyNode::ExprDict(_) - | AnyNode::ExprSet(_) - | AnyNode::ExprListComp(_) - | AnyNode::ExprSetComp(_) - | AnyNode::ExprDictComp(_) - | AnyNode::ExprGeneratorExp(_) - | AnyNode::ExprAwait(_) - | AnyNode::ExprYield(_) - | AnyNode::ExprYieldFrom(_) - | AnyNode::ExprCompare(_) - | AnyNode::ExprCall(_) - | AnyNode::ExprFormattedValue(_) - | AnyNode::ExprJoinedStr(_) - | AnyNode::ExprConstant(_) - | AnyNode::ExprAttribute(_) - | AnyNode::ExprSubscript(_) - | AnyNode::ExprStarred(_) - | AnyNode::ExprName(_) - | AnyNode::ExprList(_) - | AnyNode::ExprTuple(_) - | AnyNode::ExprSlice(_) - | AnyNode::ExprLineMagic(_) - | AnyNode::PatternMatchValue(_) - | AnyNode::PatternMatchSingleton(_) - | AnyNode::PatternMatchSequence(_) - | AnyNode::PatternMatchMapping(_) - | AnyNode::PatternMatchClass(_) - | AnyNode::PatternMatchStar(_) - | AnyNode::PatternMatchAs(_) - | AnyNode::PatternMatchOr(_) - | AnyNode::ExceptHandlerExceptHandler(_) | AnyNode::Comprehension(_) | AnyNode::Arguments(_) | AnyNode::Arg(_) @@ -668,10 +572,6 @@ impl AnyNode { self.as_ref().is_except_handler() } - pub const fn is_type_ignore(&self) -> bool { - self.as_ref().is_type_ignore() - } - pub const fn as_ref(&self) -> AnyNodeRef { match self { Self::ModModule(node) => AnyNodeRef::ModModule(node), @@ -744,7 +644,6 @@ impl AnyNode { Self::PatternMatchStar(node) => AnyNodeRef::PatternMatchStar(node), Self::PatternMatchAs(node) => AnyNodeRef::PatternMatchAs(node), Self::PatternMatchOr(node) => AnyNodeRef::PatternMatchOr(node), - Self::TypeIgnoreTypeIgnore(node) => AnyNodeRef::TypeIgnoreTypeIgnore(node), Self::Comprehension(node) => AnyNodeRef::Comprehension(node), Self::Arguments(node) => AnyNodeRef::Arguments(node), Self::Arg(node) => AnyNodeRef::Arg(node), @@ -2755,34 +2654,6 @@ impl AstNode for ast::PatternMatchOr { AnyNode::from(self) } } -impl AstNode for ast::TypeIgnoreTypeIgnore { - fn cast(kind: AnyNode) -> Option - where - Self: Sized, - { - if let AnyNode::TypeIgnoreTypeIgnore(node) = kind { - Some(node) - } else { - None - } - } - - fn cast_ref(kind: AnyNodeRef) -> Option<&Self> { - if let AnyNodeRef::TypeIgnoreTypeIgnore(node) = kind { - Some(node) - } else { - None - } - } - - fn as_any_node_ref(&self) -> AnyNodeRef { - AnyNodeRef::from(self) - } - - fn into_any_node(self) -> AnyNode { - AnyNode::from(self) - } -} impl AstNode for Comprehension { fn cast(kind: AnyNode) -> Option @@ -3226,14 +3097,6 @@ impl From for AnyNode { } } -impl From for AnyNode { - fn from(ignore: TypeIgnore) -> Self { - match ignore { - TypeIgnore::TypeIgnore(ignore) => AnyNode::TypeIgnoreTypeIgnore(ignore), - } - } -} - impl From for AnyNode { fn from(node: ast::ModModule) -> Self { AnyNode::ModModule(node) @@ -3660,12 +3523,6 @@ impl From for AnyNode { } } -impl From for AnyNode { - fn from(node: ast::TypeIgnoreTypeIgnore) -> Self { - AnyNode::TypeIgnoreTypeIgnore(node) - } -} - impl From for AnyNode { fn from(node: Comprehension) -> Self { AnyNode::Comprehension(node) @@ -3802,7 +3659,6 @@ impl Ranged for AnyNode { AnyNode::PatternMatchStar(node) => node.range(), AnyNode::PatternMatchAs(node) => node.range(), AnyNode::PatternMatchOr(node) => node.range(), - AnyNode::TypeIgnoreTypeIgnore(node) => node.range(), AnyNode::Comprehension(node) => node.range(), AnyNode::Arguments(node) => node.range(), AnyNode::Arg(node) => node.range(), @@ -3892,7 +3748,6 @@ pub enum AnyNodeRef<'a> { PatternMatchStar(&'a ast::PatternMatchStar), PatternMatchAs(&'a ast::PatternMatchAs), PatternMatchOr(&'a ast::PatternMatchOr), - TypeIgnoreTypeIgnore(&'a ast::TypeIgnoreTypeIgnore), Comprehension(&'a Comprehension), Arguments(&'a Arguments), Arg(&'a Arg), @@ -3981,7 +3836,6 @@ impl AnyNodeRef<'_> { AnyNodeRef::PatternMatchStar(node) => NonNull::from(*node).cast(), AnyNodeRef::PatternMatchAs(node) => NonNull::from(*node).cast(), AnyNodeRef::PatternMatchOr(node) => NonNull::from(*node).cast(), - AnyNodeRef::TypeIgnoreTypeIgnore(node) => NonNull::from(*node).cast(), AnyNodeRef::Comprehension(node) => NonNull::from(*node).cast(), AnyNodeRef::Arguments(node) => NonNull::from(*node).cast(), AnyNodeRef::Arg(node) => NonNull::from(*node).cast(), @@ -4076,7 +3930,6 @@ impl AnyNodeRef<'_> { AnyNodeRef::PatternMatchStar(_) => NodeKind::PatternMatchStar, AnyNodeRef::PatternMatchAs(_) => NodeKind::PatternMatchAs, AnyNodeRef::PatternMatchOr(_) => NodeKind::PatternMatchOr, - AnyNodeRef::TypeIgnoreTypeIgnore(_) => NodeKind::TypeIgnoreTypeIgnore, AnyNodeRef::Comprehension(_) => NodeKind::Comprehension, AnyNodeRef::Arguments(_) => NodeKind::Arguments, AnyNodeRef::Arg(_) => NodeKind::Arg, @@ -4166,7 +4019,6 @@ impl AnyNodeRef<'_> { | AnyNodeRef::PatternMatchStar(_) | AnyNodeRef::PatternMatchAs(_) | AnyNodeRef::PatternMatchOr(_) - | AnyNodeRef::TypeIgnoreTypeIgnore(_) | AnyNodeRef::Comprehension(_) | AnyNodeRef::Arguments(_) | AnyNodeRef::Arg(_) @@ -4256,7 +4108,6 @@ impl AnyNodeRef<'_> { | AnyNodeRef::PatternMatchStar(_) | AnyNodeRef::PatternMatchAs(_) | AnyNodeRef::PatternMatchOr(_) - | AnyNodeRef::TypeIgnoreTypeIgnore(_) | AnyNodeRef::Comprehension(_) | AnyNodeRef::Arguments(_) | AnyNodeRef::Arg(_) @@ -4346,7 +4197,6 @@ impl AnyNodeRef<'_> { | AnyNodeRef::PatternMatchStar(_) | AnyNodeRef::PatternMatchAs(_) | AnyNodeRef::PatternMatchOr(_) - | AnyNodeRef::TypeIgnoreTypeIgnore(_) | AnyNodeRef::Comprehension(_) | AnyNodeRef::Arguments(_) | AnyNodeRef::Arg(_) @@ -4436,7 +4286,6 @@ impl AnyNodeRef<'_> { | AnyNodeRef::ExprSlice(_) | AnyNodeRef::ExprLineMagic(_) | AnyNodeRef::ExceptHandlerExceptHandler(_) - | AnyNodeRef::TypeIgnoreTypeIgnore(_) | AnyNodeRef::Comprehension(_) | AnyNodeRef::Arguments(_) | AnyNodeRef::Arg(_) @@ -4526,97 +4375,6 @@ impl AnyNodeRef<'_> { | AnyNodeRef::PatternMatchStar(_) | AnyNodeRef::PatternMatchAs(_) | AnyNodeRef::PatternMatchOr(_) - | AnyNodeRef::TypeIgnoreTypeIgnore(_) - | AnyNodeRef::Comprehension(_) - | AnyNodeRef::Arguments(_) - | AnyNodeRef::Arg(_) - | AnyNodeRef::ArgWithDefault(_) - | AnyNodeRef::Keyword(_) - | AnyNodeRef::Alias(_) - | AnyNodeRef::WithItem(_) - | AnyNodeRef::MatchCase(_) - | AnyNodeRef::Decorator(_) - | AnyNodeRef::TypeParamTypeVar(_) - | AnyNodeRef::TypeParamTypeVarTuple(_) - | AnyNodeRef::TypeParamParamSpec(_) - | AnyNodeRef::ElifElseClause(_) => false, - } - } - - pub const fn is_type_ignore(self) -> bool { - match self { - AnyNodeRef::TypeIgnoreTypeIgnore(_) => true, - - AnyNodeRef::ModModule(_) - | AnyNodeRef::ModInteractive(_) - | AnyNodeRef::ModExpression(_) - | AnyNodeRef::ModFunctionType(_) - | AnyNodeRef::StmtFunctionDef(_) - | AnyNodeRef::StmtAsyncFunctionDef(_) - | AnyNodeRef::StmtClassDef(_) - | AnyNodeRef::StmtReturn(_) - | AnyNodeRef::StmtDelete(_) - | AnyNodeRef::StmtTypeAlias(_) - | AnyNodeRef::StmtAssign(_) - | AnyNodeRef::StmtAugAssign(_) - | AnyNodeRef::StmtAnnAssign(_) - | AnyNodeRef::StmtFor(_) - | AnyNodeRef::StmtAsyncFor(_) - | AnyNodeRef::StmtWhile(_) - | AnyNodeRef::StmtIf(_) - | AnyNodeRef::StmtWith(_) - | AnyNodeRef::StmtAsyncWith(_) - | AnyNodeRef::StmtMatch(_) - | AnyNodeRef::StmtRaise(_) - | AnyNodeRef::StmtTry(_) - | AnyNodeRef::StmtTryStar(_) - | AnyNodeRef::StmtAssert(_) - | AnyNodeRef::StmtImport(_) - | AnyNodeRef::StmtImportFrom(_) - | AnyNodeRef::StmtGlobal(_) - | AnyNodeRef::StmtNonlocal(_) - | AnyNodeRef::StmtExpr(_) - | AnyNodeRef::StmtPass(_) - | AnyNodeRef::StmtBreak(_) - | AnyNodeRef::StmtContinue(_) - | AnyNodeRef::StmtLineMagic(_) - | AnyNodeRef::ExprBoolOp(_) - | AnyNodeRef::ExprNamedExpr(_) - | AnyNodeRef::ExprBinOp(_) - | AnyNodeRef::ExprUnaryOp(_) - | AnyNodeRef::ExprLambda(_) - | AnyNodeRef::ExprIfExp(_) - | AnyNodeRef::ExprDict(_) - | AnyNodeRef::ExprSet(_) - | AnyNodeRef::ExprListComp(_) - | AnyNodeRef::ExprSetComp(_) - | AnyNodeRef::ExprDictComp(_) - | AnyNodeRef::ExprGeneratorExp(_) - | AnyNodeRef::ExprAwait(_) - | AnyNodeRef::ExprYield(_) - | AnyNodeRef::ExprYieldFrom(_) - | AnyNodeRef::ExprCompare(_) - | AnyNodeRef::ExprCall(_) - | AnyNodeRef::ExprFormattedValue(_) - | AnyNodeRef::ExprJoinedStr(_) - | AnyNodeRef::ExprConstant(_) - | AnyNodeRef::ExprAttribute(_) - | AnyNodeRef::ExprSubscript(_) - | AnyNodeRef::ExprStarred(_) - | AnyNodeRef::ExprName(_) - | AnyNodeRef::ExprList(_) - | AnyNodeRef::ExprTuple(_) - | AnyNodeRef::ExprSlice(_) - | AnyNodeRef::ExprLineMagic(_) - | AnyNodeRef::PatternMatchValue(_) - | AnyNodeRef::PatternMatchSingleton(_) - | AnyNodeRef::PatternMatchSequence(_) - | AnyNodeRef::PatternMatchMapping(_) - | AnyNodeRef::PatternMatchClass(_) - | AnyNodeRef::PatternMatchStar(_) - | AnyNodeRef::PatternMatchAs(_) - | AnyNodeRef::PatternMatchOr(_) - | AnyNodeRef::ExceptHandlerExceptHandler(_) | AnyNodeRef::Comprehension(_) | AnyNodeRef::Arguments(_) | AnyNodeRef::Arg(_) @@ -5090,12 +4848,6 @@ impl<'a> From<&'a ast::PatternMatchOr> for AnyNodeRef<'a> { } } -impl<'a> From<&'a ast::TypeIgnoreTypeIgnore> for AnyNodeRef<'a> { - fn from(node: &'a ast::TypeIgnoreTypeIgnore) -> Self { - AnyNodeRef::TypeIgnoreTypeIgnore(node) - } -} - impl<'a> From<&'a Decorator> for AnyNodeRef<'a> { fn from(node: &'a Decorator) -> Self { AnyNodeRef::Decorator(node) @@ -5237,14 +4989,6 @@ impl<'a> From<&'a ExceptHandler> for AnyNodeRef<'a> { } } -impl<'a> From<&'a TypeIgnore> for AnyNodeRef<'a> { - fn from(ignore: &'a TypeIgnore) -> Self { - match ignore { - TypeIgnore::TypeIgnore(ignore) => AnyNodeRef::TypeIgnoreTypeIgnore(ignore), - } - } -} - impl<'a> From<&'a Comprehension> for AnyNodeRef<'a> { fn from(node: &'a Comprehension) -> Self { AnyNodeRef::Comprehension(node) @@ -5359,7 +5103,6 @@ impl Ranged for AnyNodeRef<'_> { AnyNodeRef::PatternMatchStar(node) => node.range(), AnyNodeRef::PatternMatchAs(node) => node.range(), AnyNodeRef::PatternMatchOr(node) => node.range(), - AnyNodeRef::TypeIgnoreTypeIgnore(node) => node.range(), AnyNodeRef::Comprehension(node) => node.range(), AnyNodeRef::Arguments(node) => node.range(), AnyNodeRef::Arg(node) => node.range(), diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index f42f831c763a6..a8ef33c383313 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -20,7 +20,6 @@ pub enum Mod { pub struct ModModule { pub range: TextRange, pub body: Vec, - pub type_ignores: Vec, } impl From for Mod { @@ -2037,26 +2036,6 @@ impl From for Pattern { } } -/// See also [type_ignore](https://docs.python.org/3/library/ast.html#ast.type_ignore) -#[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum TypeIgnore { - TypeIgnore(TypeIgnoreTypeIgnore), -} - -/// See also [TypeIgnore](https://docs.python.org/3/library/ast.html#ast.TypeIgnore) -#[derive(Clone, Debug, PartialEq)] -pub struct TypeIgnoreTypeIgnore { - pub range: TextRange, - pub lineno: Int, - pub tag: String, -} - -impl From for TypeIgnore { - fn from(payload: TypeIgnoreTypeIgnore) -> Self { - TypeIgnore::TypeIgnore(payload) - } -} - /// See also [type_param](https://docs.python.org/3/library/ast.html#ast.type_param) #[derive(Clone, Debug, PartialEq, is_macro::Is)] pub enum TypeParam { @@ -2993,18 +2972,6 @@ impl Ranged for crate::Pattern { } } -impl Ranged for crate::nodes::TypeIgnoreTypeIgnore { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::TypeIgnore { - fn range(&self) -> TextRange { - match self { - Self::TypeIgnore(node) => node.range(), - } - } -} impl Ranged for crate::nodes::TypeParamTypeVar { fn range(&self) -> TextRange { self.range @@ -3055,5 +3022,5 @@ mod size_assertions { assert_eq_size!(Expr, [u8; 80]); assert_eq_size!(Constant, [u8; 32]); assert_eq_size!(Pattern, [u8; 96]); - assert_eq_size!(Mod, [u8; 64]); + assert_eq_size!(Mod, [u8; 48]); } diff --git a/crates/ruff_python_ast/src/visitor/preorder.rs b/crates/ruff_python_ast/src/visitor/preorder.rs index 64f804d9dfd98..dc988d68acb92 100644 --- a/crates/ruff_python_ast/src/visitor/preorder.rs +++ b/crates/ruff_python_ast/src/visitor/preorder.rs @@ -1,7 +1,7 @@ use crate::{ self as ast, Alias, Arg, ArgWithDefault, Arguments, BoolOp, CmpOp, Comprehension, Constant, Decorator, ElifElseClause, ExceptHandler, Expr, Keyword, MatchCase, Mod, Operator, Pattern, - Stmt, TypeIgnore, TypeParam, TypeParamTypeVar, UnaryOp, WithItem, + Stmt, TypeParam, TypeParamTypeVar, UnaryOp, WithItem, }; /// Visitor that traverses all nodes recursively in pre-order. @@ -96,10 +96,6 @@ pub trait PreorderVisitor<'a> { walk_body(self, body); } - fn visit_type_ignore(&mut self, type_ignore: &'a TypeIgnore) { - walk_type_ignore(self, type_ignore); - } - fn visit_elif_else_clause(&mut self, elif_else_clause: &'a ElifElseClause) { walk_elif_else_clause(self, elif_else_clause); } @@ -110,15 +106,8 @@ where V: PreorderVisitor<'a> + ?Sized, { match module { - Mod::Module(ast::ModModule { - body, - range: _, - type_ignores, - }) => { + Mod::Module(ast::ModModule { body, range: _ }) => { visitor.visit_body(body); - for ignore in type_ignores { - visitor.visit_type_ignore(ignore); - } } Mod::Interactive(ast::ModInteractive { body, range: _ }) => visitor.visit_body(body), Mod::Expression(ast::ModExpression { body, range: _ }) => visitor.visit_expr(body), @@ -941,13 +930,6 @@ where } } -#[inline] -pub fn walk_type_ignore<'a, V>(_visitor: &mut V, _type_ignore: &'a TypeIgnore) -where - V: PreorderVisitor<'a> + ?Sized, -{ -} - pub fn walk_bool_op<'a, V>(_visitor: &mut V, _bool_op: &'a BoolOp) where V: PreorderVisitor<'a> + ?Sized, diff --git a/crates/ruff_python_ast/tests/preorder.rs b/crates/ruff_python_ast/tests/preorder.rs index 990cdefc3a4b2..a2bc08c42cd1a 100644 --- a/crates/ruff_python_ast/tests/preorder.rs +++ b/crates/ruff_python_ast/tests/preorder.rs @@ -5,12 +5,12 @@ use insta::assert_snapshot; use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::visitor::preorder::{ 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_type_param, walk_with_item, PreorderVisitor, + walk_keyword, walk_match_case, walk_module, walk_pattern, walk_stmt, walk_type_param, + walk_with_item, PreorderVisitor, }; use ruff_python_ast::{ Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant, ExceptHandler, Expr, Keyword, - MatchCase, Mod, Operator, Pattern, Stmt, TypeIgnore, TypeParam, UnaryOp, WithItem, + MatchCase, Mod, Operator, Pattern, Stmt, TypeParam, UnaryOp, WithItem, }; use ruff_python_parser::lexer::lex; use ruff_python_parser::{parse_tokens, Mode}; @@ -273,12 +273,6 @@ impl PreorderVisitor<'_> for RecordVisitor { self.exit_node(); } - fn visit_type_ignore(&mut self, type_ignore: &TypeIgnore) { - self.enter_node(type_ignore); - walk_type_ignore(self, type_ignore); - self.exit_node(); - } - fn visit_type_param(&mut self, type_param: &TypeParam) { self.enter_node(type_param); walk_type_param(self, type_param); diff --git a/crates/ruff_python_ast/tests/visitor.rs b/crates/ruff_python_ast/tests/visitor.rs index 85e5c7f13a599..c3eeb4b0c9cb7 100644 --- a/crates/ruff_python_ast/tests/visitor.rs +++ b/crates/ruff_python_ast/tests/visitor.rs @@ -144,11 +144,7 @@ where V: Visitor<'a> + ?Sized, { match module { - ast::Mod::Module(ast::ModModule { - body, - range: _, - type_ignores: _, - }) => { + ast::Mod::Module(ast::ModModule { body, range: _ }) => { visitor.visit_body(body); } ast::Mod::Interactive(ast::ModInteractive { body, range: _ }) => { diff --git a/crates/ruff_python_formatter/src/generated.rs b/crates/ruff_python_formatter/src/generated.rs index c41ac16c651d6..2da49973fcddd 100644 --- a/crates/ruff_python_formatter/src/generated.rs +++ b/crates/ruff_python_formatter/src/generated.rs @@ -2657,46 +2657,6 @@ impl<'ast> IntoFormat> for ast::PatternMatchOr { } } -impl FormatRule> - for crate::other::type_ignore_type_ignore::FormatTypeIgnoreTypeIgnore -{ - #[inline] - fn fmt( - &self, - node: &ast::TypeIgnoreTypeIgnore, - f: &mut Formatter>, - ) -> FormatResult<()> { - FormatNodeRule::::fmt(self, node, f) - } -} -impl<'ast> AsFormat> for ast::TypeIgnoreTypeIgnore { - type Format<'a> = FormatRefWithRule< - 'a, - ast::TypeIgnoreTypeIgnore, - crate::other::type_ignore_type_ignore::FormatTypeIgnoreTypeIgnore, - PyFormatContext<'ast>, - >; - fn format(&self) -> Self::Format<'_> { - FormatRefWithRule::new( - self, - crate::other::type_ignore_type_ignore::FormatTypeIgnoreTypeIgnore::default(), - ) - } -} -impl<'ast> IntoFormat> for ast::TypeIgnoreTypeIgnore { - type Format = FormatOwnedWithRule< - ast::TypeIgnoreTypeIgnore, - crate::other::type_ignore_type_ignore::FormatTypeIgnoreTypeIgnore, - PyFormatContext<'ast>, - >; - fn into_format(self) -> Self::Format { - FormatOwnedWithRule::new( - self, - crate::other::type_ignore_type_ignore::FormatTypeIgnoreTypeIgnore::default(), - ) - } -} - impl FormatRule> for crate::other::comprehension::FormatComprehension { diff --git a/crates/ruff_python_formatter/src/module/mod_module.rs b/crates/ruff_python_formatter/src/module/mod_module.rs index a8ea713bb84a9..61556fe1ec802 100644 --- a/crates/ruff_python_formatter/src/module/mod_module.rs +++ b/crates/ruff_python_formatter/src/module/mod_module.rs @@ -9,13 +9,7 @@ pub struct FormatModModule; impl FormatNodeRule for FormatModModule { fn fmt_fields(&self, item: &ModModule, f: &mut PyFormatter) -> FormatResult<()> { - let ModModule { - range: _, - body, - type_ignores, - } = item; - // https://docs.python.org/3/library/ast.html#ast-helpers - debug_assert!(type_ignores.is_empty()); + let ModModule { range: _, body } = item; write!( f, [ diff --git a/crates/ruff_python_formatter/src/other/mod.rs b/crates/ruff_python_formatter/src/other/mod.rs index 672e3cda9b81a..aedd4c6872fd1 100644 --- a/crates/ruff_python_formatter/src/other/mod.rs +++ b/crates/ruff_python_formatter/src/other/mod.rs @@ -9,5 +9,4 @@ pub(crate) mod except_handler_except_handler; pub(crate) mod identifier; pub(crate) mod keyword; pub(crate) mod match_case; -pub(crate) mod type_ignore_type_ignore; pub(crate) mod with_item; diff --git a/crates/ruff_python_formatter/src/other/type_ignore_type_ignore.rs b/crates/ruff_python_formatter/src/other/type_ignore_type_ignore.rs deleted file mode 100644 index 7500eafb1b8f3..0000000000000 --- a/crates/ruff_python_formatter/src/other/type_ignore_type_ignore.rs +++ /dev/null @@ -1,12 +0,0 @@ -use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; -use ruff_formatter::{write, Buffer, FormatResult}; -use ruff_python_ast::TypeIgnoreTypeIgnore; - -#[derive(Default)] -pub struct FormatTypeIgnoreTypeIgnore; - -impl FormatNodeRule for FormatTypeIgnoreTypeIgnore { - fn fmt_fields(&self, item: &TypeIgnoreTypeIgnore, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [not_yet_implemented(item)]) - } -} diff --git a/crates/ruff_python_parser/src/python.lalrpop b/crates/ruff_python_parser/src/python.lalrpop index 89aad05fcc339..a5a9444f00ca7 100644 --- a/crates/ruff_python_parser/src/python.lalrpop +++ b/crates/ruff_python_parser/src/python.lalrpop @@ -21,7 +21,7 @@ grammar(mode: Mode); // For each public entry point, a full parse table is generated. // By having only a single pub function, we reduce this to one. pub(crate) Top: ast::Mod = { - StartModule => ast::ModModule { body, type_ignores: vec![], range: (start..end).into() }.into(), + StartModule => ast::ModModule { body, range: (start..end).into() }.into(), StartInteractive => ast::ModInteractive { body, range: (start..end).into() }.into(), StartExpression ("\n")* => ast::ModExpression { body: Box::new(body), range: (start..end).into() }.into() }; diff --git a/crates/ruff_python_parser/src/python.rs b/crates/ruff_python_parser/src/python.rs index 116ef566cec9e..248e10800be7a 100644 --- a/crates/ruff_python_parser/src/python.rs +++ b/crates/ruff_python_parser/src/python.rs @@ -1,5 +1,5 @@ // auto-generated: "lalrpop 0.20.0" -// sha3: bf0ea34f78939474a89bc0d4b6e7c14f370a2d2cd2ca8b98bd5aefdae0e1d5f1 +// sha3: 76f8cd8ac95bef60488dc5962346273abca535cd4aa194edd11cda998a4b211e use num_bigint::BigInt; use ruff_text_size::TextSize; use ruff_python_ast::{self as ast, Ranged, MagicKind}; @@ -30770,7 +30770,7 @@ fn __action1< (_, end, _): (TextSize, TextSize, TextSize), ) -> ast::Mod { - ast::ModModule { body, type_ignores: vec![], range: (start..end).into() }.into() + ast::ModModule { body, range: (start..end).into() }.into() } #[allow(unused_variables)] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__jupyter_magic.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__jupyter_magic.snap index ddbbe8a65d8d5..cceacf53efe9d 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__jupyter_magic.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__jupyter_magic.snap @@ -347,6 +347,5 @@ Module( }, ), ], - type_ignores: [], }, )