diff --git a/Cargo.lock b/Cargo.lock index 2453977a0a..2dd4861dd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2102,7 +2102,7 @@ dependencies = [ [[package]] name = "ruff_text_size" version = "0.0.0" -source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=f60e204b73b95bdb6ce87ccd0de34081b4a17c11#f60e204b73b95bdb6ce87ccd0de34081b4a17c11" +source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=8078663b6c914c1cb86993e427764f7c422fc12c#8078663b6c914c1cb86993e427764f7c422fc12c" dependencies = [ "schemars", "serde", @@ -2180,7 +2180,7 @@ dependencies = [ [[package]] name = "rustpython-ast" version = "0.2.0" -source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=f60e204b73b95bdb6ce87ccd0de34081b4a17c11#f60e204b73b95bdb6ce87ccd0de34081b4a17c11" +source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=8078663b6c914c1cb86993e427764f7c422fc12c#8078663b6c914c1cb86993e427764f7c422fc12c" dependencies = [ "is-macro", "num-bigint", @@ -2191,7 +2191,7 @@ dependencies = [ [[package]] name = "rustpython-format" version = "0.2.0" -source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=f60e204b73b95bdb6ce87ccd0de34081b4a17c11#f60e204b73b95bdb6ce87ccd0de34081b4a17c11" +source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=8078663b6c914c1cb86993e427764f7c422fc12c#8078663b6c914c1cb86993e427764f7c422fc12c" dependencies = [ "bitflags 2.3.1", "itertools", @@ -2203,7 +2203,7 @@ dependencies = [ [[package]] name = "rustpython-literal" version = "0.2.0" -source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=f60e204b73b95bdb6ce87ccd0de34081b4a17c11#f60e204b73b95bdb6ce87ccd0de34081b4a17c11" +source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=8078663b6c914c1cb86993e427764f7c422fc12c#8078663b6c914c1cb86993e427764f7c422fc12c" dependencies = [ "hexf-parse", "is-macro", @@ -2215,7 +2215,7 @@ dependencies = [ [[package]] name = "rustpython-parser" version = "0.2.0" -source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=f60e204b73b95bdb6ce87ccd0de34081b4a17c11#f60e204b73b95bdb6ce87ccd0de34081b4a17c11" +source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=8078663b6c914c1cb86993e427764f7c422fc12c#8078663b6c914c1cb86993e427764f7c422fc12c" dependencies = [ "anyhow", "is-macro", @@ -2238,7 +2238,7 @@ dependencies = [ [[package]] name = "rustpython-parser-core" version = "0.2.0" -source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=f60e204b73b95bdb6ce87ccd0de34081b4a17c11#f60e204b73b95bdb6ce87ccd0de34081b4a17c11" +source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=8078663b6c914c1cb86993e427764f7c422fc12c#8078663b6c914c1cb86993e427764f7c422fc12c" dependencies = [ "is-macro", "memchr", diff --git a/Cargo.toml b/Cargo.toml index c4d9205169..4066cb9c1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,16 +49,15 @@ toml = { version = "0.7.2" } # v0.0.1 libcst = { git = "https://github.com/charliermarsh/LibCST", rev = "80e4c1399f95e5beb532fdd1e209ad2dbb470438" } -# v0.0.3 -ruff_text_size = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "f60e204b73b95bdb6ce87ccd0de34081b4a17c11" } -# v0.0.3 -rustpython-ast = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "f60e204b73b95bdb6ce87ccd0de34081b4a17c11" , default-features = false, features = ["all-nodes-with-ranges", "num-bigint"]} -# v0.0.3 -rustpython-format = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "f60e204b73b95bdb6ce87ccd0de34081b4a17c11", default-features = false, features = ["num-bigint"] } -# v0.0.3 -rustpython-literal = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "f60e204b73b95bdb6ce87ccd0de34081b4a17c11", default-features = false } -# v0.0.3 -rustpython-parser = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "f60e204b73b95bdb6ce87ccd0de34081b4a17c11" , default-features = false, features = ["full-lexer", "all-nodes-with-ranges", "num-bigint"] } + +# Please tag the RustPython version everytime you update its revision here. +# Tagging the version ensures that older ruff versions continue to build from source even when we rebase our RustPython fork. +# Current tag: v0.0.6 +ruff_text_size = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "8078663b6c914c1cb86993e427764f7c422fc12c" } +rustpython-ast = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "8078663b6c914c1cb86993e427764f7c422fc12c" , default-features = false, features = ["num-bigint"]} +rustpython-format = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "8078663b6c914c1cb86993e427764f7c422fc12c", default-features = false, features = ["num-bigint"] } +rustpython-literal = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "8078663b6c914c1cb86993e427764f7c422fc12c", default-features = false } +rustpython-parser = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "8078663b6c914c1cb86993e427764f7c422fc12c" , default-features = false, features = ["full-lexer", "num-bigint"] } [profile.release] lto = "fat" diff --git a/crates/ruff/src/rules/pylint/rules/compare_to_empty_string.rs b/crates/ruff/src/rules/pylint/rules/compare_to_empty_string.rs index 078feea363..3e2b96e0a4 100644 --- a/crates/ruff/src/rules/pylint/rules/compare_to_empty_string.rs +++ b/crates/ruff/src/rules/pylint/rules/compare_to_empty_string.rs @@ -68,7 +68,7 @@ pub(crate) fn compare_to_empty_string( let mut first = true; for ((lhs, rhs), op) in std::iter::once(left) .chain(comparators.iter()) - .tuple_windows::<(&Expr<_>, &Expr<_>)>() + .tuple_windows::<(&Expr, &Expr)>() .zip(ops) { if let Ok(op) = EmptyStringCmpOp::try_from(op) { diff --git a/crates/ruff_python_ast/src/node.rs b/crates/ruff_python_ast/src/node.rs index 9928fa5d2a..c5b50e71eb 100644 --- a/crates/ruff_python_ast/src/node.rs +++ b/crates/ruff_python_ast/src/node.rs @@ -17,83 +17,83 @@ pub trait AstNode: Ranged { #[derive(Clone, Debug, is_macro::Is, PartialEq)] pub enum AnyNode { - ModModule(ModModule), - ModInteractive(ModInteractive), - ModExpression(ModExpression), - ModFunctionType(ModFunctionType), - StmtFunctionDef(StmtFunctionDef), - StmtAsyncFunctionDef(StmtAsyncFunctionDef), - StmtClassDef(StmtClassDef), - StmtReturn(StmtReturn), - StmtDelete(StmtDelete), - StmtAssign(StmtAssign), - StmtAugAssign(StmtAugAssign), - StmtAnnAssign(StmtAnnAssign), - StmtFor(StmtFor), - StmtAsyncFor(StmtAsyncFor), - StmtWhile(StmtWhile), - StmtIf(StmtIf), - StmtWith(StmtWith), - StmtAsyncWith(StmtAsyncWith), - StmtMatch(StmtMatch), - StmtRaise(StmtRaise), - StmtTry(StmtTry), - StmtTryStar(StmtTryStar), - StmtAssert(StmtAssert), - StmtImport(StmtImport), - StmtImportFrom(StmtImportFrom), - StmtGlobal(StmtGlobal), - StmtNonlocal(StmtNonlocal), - StmtExpr(StmtExpr), - StmtPass(StmtPass), - StmtBreak(StmtBreak), - StmtContinue(StmtContinue), - ExprBoolOp(ExprBoolOp), - ExprNamedExpr(ExprNamedExpr), - ExprBinOp(ExprBinOp), - ExprUnaryOp(ExprUnaryOp), - ExprLambda(ExprLambda), - ExprIfExp(ExprIfExp), - ExprDict(ExprDict), - ExprSet(ExprSet), - ExprListComp(ExprListComp), - ExprSetComp(ExprSetComp), - ExprDictComp(ExprDictComp), - ExprGeneratorExp(ExprGeneratorExp), - ExprAwait(ExprAwait), - ExprYield(ExprYield), - ExprYieldFrom(ExprYieldFrom), - ExprCompare(ExprCompare), - ExprCall(ExprCall), - ExprFormattedValue(ExprFormattedValue), - ExprJoinedStr(ExprJoinedStr), - ExprConstant(ExprConstant), - ExprAttribute(ExprAttribute), - ExprSubscript(ExprSubscript), - ExprStarred(ExprStarred), - ExprName(ExprName), - ExprList(ExprList), - ExprTuple(ExprTuple), - ExprSlice(ExprSlice), - ExceptHandlerExceptHandler(ExceptHandlerExceptHandler), - PatternMatchValue(PatternMatchValue), - PatternMatchSingleton(PatternMatchSingleton), - PatternMatchSequence(PatternMatchSequence), - PatternMatchMapping(PatternMatchMapping), - PatternMatchClass(PatternMatchClass), - PatternMatchStar(PatternMatchStar), - PatternMatchAs(PatternMatchAs), - PatternMatchOr(PatternMatchOr), - TypeIgnoreTypeIgnore(TypeIgnoreTypeIgnore), - Comprehension(Comprehension), - Arguments(Arguments), - Arg(Arg), - ArgWithDefault(ArgWithDefault), - Keyword(Keyword), - Alias(Alias), - WithItem(WithItem), - MatchCase(MatchCase), - Decorator(Decorator), + ModModule(ModModule), + ModInteractive(ModInteractive), + ModExpression(ModExpression), + ModFunctionType(ModFunctionType), + StmtFunctionDef(StmtFunctionDef), + StmtAsyncFunctionDef(StmtAsyncFunctionDef), + StmtClassDef(StmtClassDef), + StmtReturn(StmtReturn), + StmtDelete(StmtDelete), + StmtAssign(StmtAssign), + StmtAugAssign(StmtAugAssign), + StmtAnnAssign(StmtAnnAssign), + StmtFor(StmtFor), + StmtAsyncFor(StmtAsyncFor), + StmtWhile(StmtWhile), + StmtIf(StmtIf), + StmtWith(StmtWith), + StmtAsyncWith(StmtAsyncWith), + StmtMatch(StmtMatch), + StmtRaise(StmtRaise), + StmtTry(StmtTry), + StmtTryStar(StmtTryStar), + StmtAssert(StmtAssert), + StmtImport(StmtImport), + StmtImportFrom(StmtImportFrom), + StmtGlobal(StmtGlobal), + StmtNonlocal(StmtNonlocal), + StmtExpr(StmtExpr), + StmtPass(StmtPass), + StmtBreak(StmtBreak), + StmtContinue(StmtContinue), + ExprBoolOp(ExprBoolOp), + ExprNamedExpr(ExprNamedExpr), + ExprBinOp(ExprBinOp), + ExprUnaryOp(ExprUnaryOp), + ExprLambda(ExprLambda), + ExprIfExp(ExprIfExp), + ExprDict(ExprDict), + ExprSet(ExprSet), + ExprListComp(ExprListComp), + ExprSetComp(ExprSetComp), + ExprDictComp(ExprDictComp), + ExprGeneratorExp(ExprGeneratorExp), + ExprAwait(ExprAwait), + ExprYield(ExprYield), + ExprYieldFrom(ExprYieldFrom), + ExprCompare(ExprCompare), + ExprCall(ExprCall), + ExprFormattedValue(ExprFormattedValue), + ExprJoinedStr(ExprJoinedStr), + ExprConstant(ExprConstant), + ExprAttribute(ExprAttribute), + ExprSubscript(ExprSubscript), + ExprStarred(ExprStarred), + ExprName(ExprName), + ExprList(ExprList), + ExprTuple(ExprTuple), + ExprSlice(ExprSlice), + ExceptHandlerExceptHandler(ExceptHandlerExceptHandler), + PatternMatchValue(PatternMatchValue), + PatternMatchSingleton(PatternMatchSingleton), + PatternMatchSequence(PatternMatchSequence), + PatternMatchMapping(PatternMatchMapping), + PatternMatchClass(PatternMatchClass), + PatternMatchStar(PatternMatchStar), + PatternMatchAs(PatternMatchAs), + PatternMatchOr(PatternMatchOr), + TypeIgnoreTypeIgnore(TypeIgnoreTypeIgnore), + Comprehension(Comprehension), + Arguments(Arguments), + Arg(Arg), + ArgWithDefault(ArgWithDefault), + Keyword(Keyword), + Alias(Alias), + WithItem(WithItem), + MatchCase(MatchCase), + Decorator(Decorator), } impl AnyNode { @@ -707,7 +707,7 @@ impl AnyNode { } } -impl AstNode for ModModule { +impl AstNode for ModModule { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -735,7 +735,7 @@ impl AstNode for ModModule { AnyNode::from(self) } } -impl AstNode for ModInteractive { +impl AstNode for ModInteractive { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -763,7 +763,7 @@ impl AstNode for ModInteractive { AnyNode::from(self) } } -impl AstNode for ModExpression { +impl AstNode for ModExpression { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -791,7 +791,7 @@ impl AstNode for ModExpression { AnyNode::from(self) } } -impl AstNode for ModFunctionType { +impl AstNode for ModFunctionType { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -819,7 +819,7 @@ impl AstNode for ModFunctionType { AnyNode::from(self) } } -impl AstNode for StmtFunctionDef { +impl AstNode for StmtFunctionDef { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -847,7 +847,7 @@ impl AstNode for StmtFunctionDef { AnyNode::from(self) } } -impl AstNode for StmtAsyncFunctionDef { +impl AstNode for StmtAsyncFunctionDef { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -875,7 +875,7 @@ impl AstNode for StmtAsyncFunctionDef { AnyNode::from(self) } } -impl AstNode for StmtClassDef { +impl AstNode for StmtClassDef { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -903,7 +903,7 @@ impl AstNode for StmtClassDef { AnyNode::from(self) } } -impl AstNode for StmtReturn { +impl AstNode for StmtReturn { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -931,7 +931,7 @@ impl AstNode for StmtReturn { AnyNode::from(self) } } -impl AstNode for StmtDelete { +impl AstNode for StmtDelete { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -959,7 +959,7 @@ impl AstNode for StmtDelete { AnyNode::from(self) } } -impl AstNode for StmtAssign { +impl AstNode for StmtAssign { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -987,7 +987,7 @@ impl AstNode for StmtAssign { AnyNode::from(self) } } -impl AstNode for StmtAugAssign { +impl AstNode for StmtAugAssign { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1015,7 +1015,7 @@ impl AstNode for StmtAugAssign { AnyNode::from(self) } } -impl AstNode for StmtAnnAssign { +impl AstNode for StmtAnnAssign { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1043,7 +1043,7 @@ impl AstNode for StmtAnnAssign { AnyNode::from(self) } } -impl AstNode for StmtFor { +impl AstNode for StmtFor { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1071,7 +1071,7 @@ impl AstNode for StmtFor { AnyNode::from(self) } } -impl AstNode for StmtAsyncFor { +impl AstNode for StmtAsyncFor { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1099,7 +1099,7 @@ impl AstNode for StmtAsyncFor { AnyNode::from(self) } } -impl AstNode for StmtWhile { +impl AstNode for StmtWhile { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1127,7 +1127,7 @@ impl AstNode for StmtWhile { AnyNode::from(self) } } -impl AstNode for StmtIf { +impl AstNode for StmtIf { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1155,7 +1155,7 @@ impl AstNode for StmtIf { AnyNode::from(self) } } -impl AstNode for StmtWith { +impl AstNode for StmtWith { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1183,7 +1183,7 @@ impl AstNode for StmtWith { AnyNode::from(self) } } -impl AstNode for StmtAsyncWith { +impl AstNode for StmtAsyncWith { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1211,7 +1211,7 @@ impl AstNode for StmtAsyncWith { AnyNode::from(self) } } -impl AstNode for StmtMatch { +impl AstNode for StmtMatch { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1239,7 +1239,7 @@ impl AstNode for StmtMatch { AnyNode::from(self) } } -impl AstNode for StmtRaise { +impl AstNode for StmtRaise { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1267,7 +1267,7 @@ impl AstNode for StmtRaise { AnyNode::from(self) } } -impl AstNode for StmtTry { +impl AstNode for StmtTry { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1295,7 +1295,7 @@ impl AstNode for StmtTry { AnyNode::from(self) } } -impl AstNode for StmtTryStar { +impl AstNode for StmtTryStar { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1323,7 +1323,7 @@ impl AstNode for StmtTryStar { AnyNode::from(self) } } -impl AstNode for StmtAssert { +impl AstNode for StmtAssert { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1351,7 +1351,7 @@ impl AstNode for StmtAssert { AnyNode::from(self) } } -impl AstNode for StmtImport { +impl AstNode for StmtImport { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1379,7 +1379,7 @@ impl AstNode for StmtImport { AnyNode::from(self) } } -impl AstNode for StmtImportFrom { +impl AstNode for StmtImportFrom { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1407,7 +1407,7 @@ impl AstNode for StmtImportFrom { AnyNode::from(self) } } -impl AstNode for StmtGlobal { +impl AstNode for StmtGlobal { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1435,7 +1435,7 @@ impl AstNode for StmtGlobal { AnyNode::from(self) } } -impl AstNode for StmtNonlocal { +impl AstNode for StmtNonlocal { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1463,7 +1463,7 @@ impl AstNode for StmtNonlocal { AnyNode::from(self) } } -impl AstNode for StmtExpr { +impl AstNode for StmtExpr { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1491,7 +1491,7 @@ impl AstNode for StmtExpr { AnyNode::from(self) } } -impl AstNode for StmtPass { +impl AstNode for StmtPass { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1519,7 +1519,7 @@ impl AstNode for StmtPass { AnyNode::from(self) } } -impl AstNode for StmtBreak { +impl AstNode for StmtBreak { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1547,7 +1547,7 @@ impl AstNode for StmtBreak { AnyNode::from(self) } } -impl AstNode for StmtContinue { +impl AstNode for StmtContinue { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1575,7 +1575,7 @@ impl AstNode for StmtContinue { AnyNode::from(self) } } -impl AstNode for ExprBoolOp { +impl AstNode for ExprBoolOp { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1603,7 +1603,7 @@ impl AstNode for ExprBoolOp { AnyNode::from(self) } } -impl AstNode for ExprNamedExpr { +impl AstNode for ExprNamedExpr { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1631,7 +1631,7 @@ impl AstNode for ExprNamedExpr { AnyNode::from(self) } } -impl AstNode for ExprBinOp { +impl AstNode for ExprBinOp { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1659,7 +1659,7 @@ impl AstNode for ExprBinOp { AnyNode::from(self) } } -impl AstNode for ExprUnaryOp { +impl AstNode for ExprUnaryOp { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1687,7 +1687,7 @@ impl AstNode for ExprUnaryOp { AnyNode::from(self) } } -impl AstNode for ExprLambda { +impl AstNode for ExprLambda { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1715,7 +1715,7 @@ impl AstNode for ExprLambda { AnyNode::from(self) } } -impl AstNode for ExprIfExp { +impl AstNode for ExprIfExp { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1743,7 +1743,7 @@ impl AstNode for ExprIfExp { AnyNode::from(self) } } -impl AstNode for ExprDict { +impl AstNode for ExprDict { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1771,7 +1771,7 @@ impl AstNode for ExprDict { AnyNode::from(self) } } -impl AstNode for ExprSet { +impl AstNode for ExprSet { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1799,7 +1799,7 @@ impl AstNode for ExprSet { AnyNode::from(self) } } -impl AstNode for ExprListComp { +impl AstNode for ExprListComp { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1827,7 +1827,7 @@ impl AstNode for ExprListComp { AnyNode::from(self) } } -impl AstNode for ExprSetComp { +impl AstNode for ExprSetComp { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1855,7 +1855,7 @@ impl AstNode for ExprSetComp { AnyNode::from(self) } } -impl AstNode for ExprDictComp { +impl AstNode for ExprDictComp { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1883,7 +1883,7 @@ impl AstNode for ExprDictComp { AnyNode::from(self) } } -impl AstNode for ExprGeneratorExp { +impl AstNode for ExprGeneratorExp { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1911,7 +1911,7 @@ impl AstNode for ExprGeneratorExp { AnyNode::from(self) } } -impl AstNode for ExprAwait { +impl AstNode for ExprAwait { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1939,7 +1939,7 @@ impl AstNode for ExprAwait { AnyNode::from(self) } } -impl AstNode for ExprYield { +impl AstNode for ExprYield { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1967,7 +1967,7 @@ impl AstNode for ExprYield { AnyNode::from(self) } } -impl AstNode for ExprYieldFrom { +impl AstNode for ExprYieldFrom { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -1995,7 +1995,7 @@ impl AstNode for ExprYieldFrom { AnyNode::from(self) } } -impl AstNode for ExprCompare { +impl AstNode for ExprCompare { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2023,7 +2023,7 @@ impl AstNode for ExprCompare { AnyNode::from(self) } } -impl AstNode for ExprCall { +impl AstNode for ExprCall { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2051,7 +2051,7 @@ impl AstNode for ExprCall { AnyNode::from(self) } } -impl AstNode for ExprFormattedValue { +impl AstNode for ExprFormattedValue { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2079,7 +2079,7 @@ impl AstNode for ExprFormattedValue { AnyNode::from(self) } } -impl AstNode for ExprJoinedStr { +impl AstNode for ExprJoinedStr { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2107,7 +2107,7 @@ impl AstNode for ExprJoinedStr { AnyNode::from(self) } } -impl AstNode for ExprConstant { +impl AstNode for ExprConstant { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2135,7 +2135,7 @@ impl AstNode for ExprConstant { AnyNode::from(self) } } -impl AstNode for ExprAttribute { +impl AstNode for ExprAttribute { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2163,7 +2163,7 @@ impl AstNode for ExprAttribute { AnyNode::from(self) } } -impl AstNode for ExprSubscript { +impl AstNode for ExprSubscript { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2191,7 +2191,7 @@ impl AstNode for ExprSubscript { AnyNode::from(self) } } -impl AstNode for ExprStarred { +impl AstNode for ExprStarred { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2219,7 +2219,7 @@ impl AstNode for ExprStarred { AnyNode::from(self) } } -impl AstNode for ExprName { +impl AstNode for ExprName { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2247,7 +2247,7 @@ impl AstNode for ExprName { AnyNode::from(self) } } -impl AstNode for ExprList { +impl AstNode for ExprList { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2275,7 +2275,7 @@ impl AstNode for ExprList { AnyNode::from(self) } } -impl AstNode for ExprTuple { +impl AstNode for ExprTuple { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2303,7 +2303,7 @@ impl AstNode for ExprTuple { AnyNode::from(self) } } -impl AstNode for ExprSlice { +impl AstNode for ExprSlice { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2331,7 +2331,7 @@ impl AstNode for ExprSlice { AnyNode::from(self) } } -impl AstNode for ExceptHandlerExceptHandler { +impl AstNode for ExceptHandlerExceptHandler { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2359,7 +2359,7 @@ impl AstNode for ExceptHandlerExceptHandler { AnyNode::from(self) } } -impl AstNode for PatternMatchValue { +impl AstNode for PatternMatchValue { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2387,7 +2387,7 @@ impl AstNode for PatternMatchValue { AnyNode::from(self) } } -impl AstNode for PatternMatchSingleton { +impl AstNode for PatternMatchSingleton { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2415,7 +2415,7 @@ impl AstNode for PatternMatchSingleton { AnyNode::from(self) } } -impl AstNode for PatternMatchSequence { +impl AstNode for PatternMatchSequence { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2443,7 +2443,7 @@ impl AstNode for PatternMatchSequence { AnyNode::from(self) } } -impl AstNode for PatternMatchMapping { +impl AstNode for PatternMatchMapping { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2471,7 +2471,7 @@ impl AstNode for PatternMatchMapping { AnyNode::from(self) } } -impl AstNode for PatternMatchClass { +impl AstNode for PatternMatchClass { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2499,7 +2499,7 @@ impl AstNode for PatternMatchClass { AnyNode::from(self) } } -impl AstNode for PatternMatchStar { +impl AstNode for PatternMatchStar { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2527,7 +2527,7 @@ impl AstNode for PatternMatchStar { AnyNode::from(self) } } -impl AstNode for PatternMatchAs { +impl AstNode for PatternMatchAs { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2555,7 +2555,7 @@ impl AstNode for PatternMatchAs { AnyNode::from(self) } } -impl AstNode for PatternMatchOr { +impl AstNode for PatternMatchOr { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2583,7 +2583,7 @@ impl AstNode for PatternMatchOr { AnyNode::from(self) } } -impl AstNode for TypeIgnoreTypeIgnore { +impl AstNode for TypeIgnoreTypeIgnore { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2612,7 +2612,7 @@ impl AstNode for TypeIgnoreTypeIgnore { } } -impl AstNode for Comprehension { +impl AstNode for Comprehension { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2640,7 +2640,7 @@ impl AstNode for Comprehension { AnyNode::from(self) } } -impl AstNode for Arguments { +impl AstNode for Arguments { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2668,7 +2668,7 @@ impl AstNode for Arguments { AnyNode::from(self) } } -impl AstNode for Arg { +impl AstNode for Arg { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2696,7 +2696,7 @@ impl AstNode for Arg { AnyNode::from(self) } } -impl AstNode for ArgWithDefault { +impl AstNode for ArgWithDefault { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2724,7 +2724,7 @@ impl AstNode for ArgWithDefault { AnyNode::from(self) } } -impl AstNode for Keyword { +impl AstNode for Keyword { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2752,7 +2752,7 @@ impl AstNode for Keyword { AnyNode::from(self) } } -impl AstNode for Alias { +impl AstNode for Alias { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2780,7 +2780,7 @@ impl AstNode for Alias { AnyNode::from(self) } } -impl AstNode for WithItem { +impl AstNode for WithItem { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2808,7 +2808,7 @@ impl AstNode for WithItem { AnyNode::from(self) } } -impl AstNode for MatchCase { +impl AstNode for MatchCase { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -2837,7 +2837,7 @@ impl AstNode for MatchCase { } } -impl AstNode for Decorator { +impl AstNode for Decorator { fn cast(kind: AnyNode) -> Option where Self: Sized, @@ -3516,83 +3516,83 @@ impl Ranged for AnyNode { #[derive(Copy, Clone, Debug, is_macro::Is, PartialEq)] pub enum AnyNodeRef<'a> { - ModModule(&'a ModModule), - ModInteractive(&'a ModInteractive), - ModExpression(&'a ModExpression), - ModFunctionType(&'a ModFunctionType), - StmtFunctionDef(&'a StmtFunctionDef), - StmtAsyncFunctionDef(&'a StmtAsyncFunctionDef), - StmtClassDef(&'a StmtClassDef), - StmtReturn(&'a StmtReturn), - StmtDelete(&'a StmtDelete), - StmtAssign(&'a StmtAssign), - StmtAugAssign(&'a StmtAugAssign), - StmtAnnAssign(&'a StmtAnnAssign), - StmtFor(&'a StmtFor), - StmtAsyncFor(&'a StmtAsyncFor), - StmtWhile(&'a StmtWhile), - StmtIf(&'a StmtIf), - StmtWith(&'a StmtWith), - StmtAsyncWith(&'a StmtAsyncWith), - StmtMatch(&'a StmtMatch), - StmtRaise(&'a StmtRaise), - StmtTry(&'a StmtTry), - StmtTryStar(&'a StmtTryStar), - StmtAssert(&'a StmtAssert), - StmtImport(&'a StmtImport), - StmtImportFrom(&'a StmtImportFrom), - StmtGlobal(&'a StmtGlobal), - StmtNonlocal(&'a StmtNonlocal), - StmtExpr(&'a StmtExpr), - StmtPass(&'a StmtPass), - StmtBreak(&'a StmtBreak), - StmtContinue(&'a StmtContinue), - ExprBoolOp(&'a ExprBoolOp), - ExprNamedExpr(&'a ExprNamedExpr), - ExprBinOp(&'a ExprBinOp), - ExprUnaryOp(&'a ExprUnaryOp), - ExprLambda(&'a ExprLambda), - ExprIfExp(&'a ExprIfExp), - ExprDict(&'a ExprDict), - ExprSet(&'a ExprSet), - ExprListComp(&'a ExprListComp), - ExprSetComp(&'a ExprSetComp), - ExprDictComp(&'a ExprDictComp), - ExprGeneratorExp(&'a ExprGeneratorExp), - ExprAwait(&'a ExprAwait), - ExprYield(&'a ExprYield), - ExprYieldFrom(&'a ExprYieldFrom), - ExprCompare(&'a ExprCompare), - ExprCall(&'a ExprCall), - ExprFormattedValue(&'a ExprFormattedValue), - ExprJoinedStr(&'a ExprJoinedStr), - ExprConstant(&'a ExprConstant), - ExprAttribute(&'a ExprAttribute), - ExprSubscript(&'a ExprSubscript), - ExprStarred(&'a ExprStarred), - ExprName(&'a ExprName), - ExprList(&'a ExprList), - ExprTuple(&'a ExprTuple), - ExprSlice(&'a ExprSlice), - ExceptHandlerExceptHandler(&'a ExceptHandlerExceptHandler), - PatternMatchValue(&'a PatternMatchValue), - PatternMatchSingleton(&'a PatternMatchSingleton), - PatternMatchSequence(&'a PatternMatchSequence), - PatternMatchMapping(&'a PatternMatchMapping), - PatternMatchClass(&'a PatternMatchClass), - PatternMatchStar(&'a PatternMatchStar), - PatternMatchAs(&'a PatternMatchAs), - PatternMatchOr(&'a PatternMatchOr), - TypeIgnoreTypeIgnore(&'a TypeIgnoreTypeIgnore), - Comprehension(&'a Comprehension), - Arguments(&'a Arguments), - Arg(&'a Arg), - ArgWithDefault(&'a ArgWithDefault), - Keyword(&'a Keyword), - Alias(&'a Alias), - WithItem(&'a WithItem), - MatchCase(&'a MatchCase), - Decorator(&'a Decorator), + ModModule(&'a ModModule), + ModInteractive(&'a ModInteractive), + ModExpression(&'a ModExpression), + ModFunctionType(&'a ModFunctionType), + StmtFunctionDef(&'a StmtFunctionDef), + StmtAsyncFunctionDef(&'a StmtAsyncFunctionDef), + StmtClassDef(&'a StmtClassDef), + StmtReturn(&'a StmtReturn), + StmtDelete(&'a StmtDelete), + StmtAssign(&'a StmtAssign), + StmtAugAssign(&'a StmtAugAssign), + StmtAnnAssign(&'a StmtAnnAssign), + StmtFor(&'a StmtFor), + StmtAsyncFor(&'a StmtAsyncFor), + StmtWhile(&'a StmtWhile), + StmtIf(&'a StmtIf), + StmtWith(&'a StmtWith), + StmtAsyncWith(&'a StmtAsyncWith), + StmtMatch(&'a StmtMatch), + StmtRaise(&'a StmtRaise), + StmtTry(&'a StmtTry), + StmtTryStar(&'a StmtTryStar), + StmtAssert(&'a StmtAssert), + StmtImport(&'a StmtImport), + StmtImportFrom(&'a StmtImportFrom), + StmtGlobal(&'a StmtGlobal), + StmtNonlocal(&'a StmtNonlocal), + StmtExpr(&'a StmtExpr), + StmtPass(&'a StmtPass), + StmtBreak(&'a StmtBreak), + StmtContinue(&'a StmtContinue), + ExprBoolOp(&'a ExprBoolOp), + ExprNamedExpr(&'a ExprNamedExpr), + ExprBinOp(&'a ExprBinOp), + ExprUnaryOp(&'a ExprUnaryOp), + ExprLambda(&'a ExprLambda), + ExprIfExp(&'a ExprIfExp), + ExprDict(&'a ExprDict), + ExprSet(&'a ExprSet), + ExprListComp(&'a ExprListComp), + ExprSetComp(&'a ExprSetComp), + ExprDictComp(&'a ExprDictComp), + ExprGeneratorExp(&'a ExprGeneratorExp), + ExprAwait(&'a ExprAwait), + ExprYield(&'a ExprYield), + ExprYieldFrom(&'a ExprYieldFrom), + ExprCompare(&'a ExprCompare), + ExprCall(&'a ExprCall), + ExprFormattedValue(&'a ExprFormattedValue), + ExprJoinedStr(&'a ExprJoinedStr), + ExprConstant(&'a ExprConstant), + ExprAttribute(&'a ExprAttribute), + ExprSubscript(&'a ExprSubscript), + ExprStarred(&'a ExprStarred), + ExprName(&'a ExprName), + ExprList(&'a ExprList), + ExprTuple(&'a ExprTuple), + ExprSlice(&'a ExprSlice), + ExceptHandlerExceptHandler(&'a ExceptHandlerExceptHandler), + PatternMatchValue(&'a PatternMatchValue), + PatternMatchSingleton(&'a PatternMatchSingleton), + PatternMatchSequence(&'a PatternMatchSequence), + PatternMatchMapping(&'a PatternMatchMapping), + PatternMatchClass(&'a PatternMatchClass), + PatternMatchStar(&'a PatternMatchStar), + PatternMatchAs(&'a PatternMatchAs), + PatternMatchOr(&'a PatternMatchOr), + TypeIgnoreTypeIgnore(&'a TypeIgnoreTypeIgnore), + Comprehension(&'a Comprehension), + Arguments(&'a Arguments), + Arg(&'a Arg), + ArgWithDefault(&'a ArgWithDefault), + Keyword(&'a Keyword), + Alias(&'a Alias), + WithItem(&'a WithItem), + MatchCase(&'a MatchCase), + Decorator(&'a Decorator), } impl AnyNodeRef<'_> { diff --git a/crates/ruff_python_ast/src/source_code/generator.rs b/crates/ruff_python_ast/src/source_code/generator.rs index 0b3ec2f5d5..e406122e2e 100644 --- a/crates/ruff_python_ast/src/source_code/generator.rs +++ b/crates/ruff_python_ast/src/source_code/generator.rs @@ -132,7 +132,7 @@ impl<'a> Generator<'a> { } } - fn body(&mut self, stmts: &[Stmt]) { + fn body(&mut self, stmts: &[Stmt]) { self.indent_depth = self.indent_depth.saturating_add(1); for stmt in stmts { self.unparse_stmt(stmt); @@ -184,13 +184,13 @@ impl<'a> Generator<'a> { self.buffer } - pub fn unparse_suite(&mut self, suite: &Suite) { + pub fn unparse_suite(&mut self, suite: &Suite) { for stmt in suite { self.unparse_stmt(stmt); } } - pub(crate) fn unparse_stmt(&mut self, ast: &Stmt) { + pub(crate) fn unparse_stmt(&mut self, ast: &Stmt) { macro_rules! statement { ($body:block) => {{ self.newline(); @@ -467,7 +467,7 @@ impl<'a> Generator<'a> { }); self.body(body); - let mut orelse_: &[Stmt] = orelse; + let mut orelse_: &[Stmt] = orelse; loop { if orelse_.len() == 1 && matches!(orelse_[0], Stmt::If(_)) { if let Stmt::If(ast::StmtIf { @@ -718,7 +718,7 @@ impl<'a> Generator<'a> { } } - fn unparse_except_handler(&mut self, ast: &ExceptHandler, star: bool) { + fn unparse_except_handler(&mut self, ast: &ExceptHandler, star: bool) { match ast { ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { type_, @@ -744,7 +744,7 @@ impl<'a> Generator<'a> { } } - fn unparse_pattern(&mut self, ast: &Pattern) { + fn unparse_pattern(&mut self, ast: &Pattern) { match ast { Pattern::MatchValue(ast::PatternMatchValue { value, @@ -831,7 +831,7 @@ impl<'a> Generator<'a> { } } - fn unparse_match_case(&mut self, ast: &MatchCase) { + fn unparse_match_case(&mut self, ast: &MatchCase) { self.p("case "); self.unparse_pattern(&ast.pattern); if let Some(guard) = &ast.guard { @@ -842,7 +842,7 @@ impl<'a> Generator<'a> { self.body(&ast.body); } - pub(crate) fn unparse_expr(&mut self, ast: &Expr, level: u8) { + pub(crate) fn unparse_expr(&mut self, ast: &Expr, level: u8) { macro_rules! opprec { ($opty:ident, $x:expr, $enu:path, $($var:ident($op:literal, $prec:ident)),*$(,)?) => { match $x { @@ -1289,7 +1289,7 @@ impl<'a> Generator<'a> { } } - fn unparse_args(&mut self, args: &Arguments) { + fn unparse_args(&mut self, args: &Arguments) { let mut first = true; for (i, arg_with_default) in args.posonlyargs.iter().chain(&args.args).enumerate() { self.p_delim(&mut first, ", "); @@ -1314,7 +1314,7 @@ impl<'a> Generator<'a> { } } - fn unparse_arg(&mut self, arg: &Arg) { + fn unparse_arg(&mut self, arg: &Arg) { self.p_id(&arg.arg); if let Some(ann) = &arg.annotation { self.p(": "); @@ -1322,7 +1322,7 @@ impl<'a> Generator<'a> { } } - fn unparse_arg_with_default(&mut self, arg_with_default: &ArgWithDefault) { + fn unparse_arg_with_default(&mut self, arg_with_default: &ArgWithDefault) { self.unparse_arg(&arg_with_default.def); if let Some(default) = &arg_with_default.default { self.p("="); @@ -1330,7 +1330,7 @@ impl<'a> Generator<'a> { } } - fn unparse_comp(&mut self, generators: &[Comprehension]) { + fn unparse_comp(&mut self, generators: &[Comprehension]) { for comp in generators { self.p(if comp.is_async { " async for " @@ -1347,18 +1347,13 @@ impl<'a> Generator<'a> { } } - fn unparse_fstring_body(&mut self, values: &[Expr], is_spec: bool) { + fn unparse_fstring_body(&mut self, values: &[Expr], is_spec: bool) { for value in values { self.unparse_fstring_elem(value, is_spec); } } - fn unparse_formatted( - &mut self, - val: &Expr, - conversion: ConversionFlag, - spec: Option<&Expr>, - ) { + fn unparse_formatted(&mut self, val: &Expr, conversion: ConversionFlag, spec: Option<&Expr>) { let mut generator = Generator::new(self.indent, self.quote, self.line_ending); generator.unparse_expr(val, precedence::FORMATTED_VALUE); let brace = if generator.buffer.starts_with('{') { @@ -1384,7 +1379,7 @@ impl<'a> Generator<'a> { self.p("}"); } - fn unparse_fstring_elem(&mut self, expr: &Expr, is_spec: bool) { + fn unparse_fstring_elem(&mut self, expr: &Expr, is_spec: bool) { match expr { Expr::Constant(ast::ExprConstant { value, .. }) => { if let Constant::Str(s) = value { @@ -1414,7 +1409,7 @@ impl<'a> Generator<'a> { self.p(&s); } - fn unparse_joinedstr(&mut self, values: &[Expr], is_spec: bool) { + fn unparse_joinedstr(&mut self, values: &[Expr], is_spec: bool) { if is_spec { self.unparse_fstring_body(values, is_spec); } else { @@ -1433,7 +1428,7 @@ impl<'a> Generator<'a> { } } - fn unparse_alias(&mut self, alias: &Alias) { + fn unparse_alias(&mut self, alias: &Alias) { self.p_id(&alias.name); if let Some(asname) = &alias.asname { self.p(" as "); @@ -1441,7 +1436,7 @@ impl<'a> Generator<'a> { } } - fn unparse_with_item(&mut self, with_item: &WithItem) { + fn unparse_with_item(&mut self, with_item: &WithItem) { self.unparse_expr(&with_item.context_expr, precedence::MAX); if let Some(optional_vars) = &with_item.optional_vars { self.p(" as ");