diff --git a/crates/ruff/src/checkers/ast/mod.rs b/crates/ruff/src/checkers/ast/mod.rs index d19a24fadc..585c7459a8 100644 --- a/crates/ruff/src/checkers/ast/mod.rs +++ b/crates/ruff/src/checkers/ast/mod.rs @@ -482,8 +482,8 @@ where self.semantic.push_scope(ScopeKind::Type); - for type_param in type_params { - self.visit_type_param(type_param); + if let Some(type_params) = type_params { + self.visit_type_params(type_params); } for parameter_with_default in parameters @@ -565,8 +565,8 @@ where self.semantic.push_scope(ScopeKind::Type); - for type_param in type_params { - self.visit_type_param(type_param); + if let Some(type_params) = type_params { + self.visit_type_params(type_params); } if let Some(arguments) = arguments { @@ -596,8 +596,8 @@ where value, }) => { self.semantic.push_scope(ScopeKind::Type); - for type_param in type_params { - self.visit_type_param(type_param); + if let Some(type_params) = type_params { + self.visit_type_params(type_params); } self.visit_expr(value); self.semantic.pop_scope(); diff --git a/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs b/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs index 2bc187126e..f909ac3fea 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs @@ -229,7 +229,7 @@ fn function( body: vec![body], decorator_list: vec![], returns: Some(Box::new(return_type)), - type_params: vec![], + type_params: None, range: TextRange::default(), }); return generator.stmt(&func); @@ -241,7 +241,7 @@ fn function( body: vec![body], decorator_list: vec![], returns: None, - type_params: vec![], + type_params: None, range: TextRange::default(), }); generator.stmt(&func) diff --git a/crates/ruff/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs b/crates/ruff/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs index 5617517b19..6ecc2db6c2 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs @@ -172,7 +172,7 @@ fn create_class_def_stmt(typename: &str, body: Vec, base_class: &Expr) -> range: TextRange::default(), }), body, - type_params: vec![], + type_params: None, decorator_list: vec![], range: TextRange::default(), } diff --git a/crates/ruff/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs b/crates/ruff/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs index 1b600bd60f..b89930e845 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs @@ -128,7 +128,7 @@ fn create_class_def_stmt( range: TextRange::default(), }), body, - type_params: vec![], + type_params: None, decorator_list: vec![], range: TextRange::default(), } diff --git a/crates/ruff_python_ast/src/comparable.rs b/crates/ruff_python_ast/src/comparable.rs index a4aa23850d..f2e0ec6f24 100644 --- a/crates/ruff_python_ast/src/comparable.rs +++ b/crates/ruff_python_ast/src/comparable.rs @@ -969,7 +969,7 @@ pub struct StmtFunctionDef<'a> { parameters: ComparableParameters<'a>, body: Vec>, decorator_list: Vec>, - type_params: Vec>, + type_params: Option>, returns: Option>, } @@ -979,7 +979,7 @@ pub struct StmtAsyncFunctionDef<'a> { parameters: ComparableParameters<'a>, body: Vec>, decorator_list: Vec>, - type_params: Vec>, + type_params: Option>, returns: Option>, } @@ -989,7 +989,7 @@ pub struct StmtClassDef<'a> { arguments: Option>, body: Vec>, decorator_list: Vec>, - type_params: Vec>, + type_params: Option>, } #[derive(Debug, PartialEq, Eq, Hash)] @@ -1005,10 +1005,23 @@ pub struct StmtDelete<'a> { #[derive(Debug, PartialEq, Eq, Hash)] pub struct StmtTypeAlias<'a> { pub name: Box>, - pub type_params: Vec>, + pub type_params: Option>, pub value: Box>, } +#[derive(Debug, PartialEq, Eq, Hash)] +pub struct ComparableTypeParams<'a> { + pub type_params: Vec>, +} + +impl<'a> From<&'a ast::TypeParams> for ComparableTypeParams<'a> { + fn from(type_params: &'a ast::TypeParams) -> Self { + Self { + type_params: type_params.iter().map(Into::into).collect(), + } + } +} + #[derive(Debug, PartialEq, Eq, Hash)] pub enum ComparableTypeParam<'a> { TypeVar(TypeParamTypeVar<'a>), @@ -1237,7 +1250,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> { body: body.iter().map(Into::into).collect(), decorator_list: decorator_list.iter().map(Into::into).collect(), returns: returns.as_ref().map(Into::into), - type_params: type_params.iter().map(Into::into).collect(), + type_params: type_params.as_ref().map(Into::into), }), ast::Stmt::AsyncFunctionDef(ast::StmtAsyncFunctionDef { name, @@ -1253,7 +1266,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> { body: body.iter().map(Into::into).collect(), decorator_list: decorator_list.iter().map(Into::into).collect(), returns: returns.as_ref().map(Into::into), - type_params: type_params.iter().map(Into::into).collect(), + type_params: type_params.as_ref().map(Into::into), }), ast::Stmt::ClassDef(ast::StmtClassDef { name, @@ -1267,7 +1280,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> { arguments: arguments.as_ref().map(Into::into), body: body.iter().map(Into::into).collect(), decorator_list: decorator_list.iter().map(Into::into).collect(), - type_params: type_params.iter().map(Into::into).collect(), + type_params: type_params.as_ref().map(Into::into), }), ast::Stmt::Return(ast::StmtReturn { value, @@ -1288,7 +1301,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> { value, }) => Self::TypeAlias(StmtTypeAlias { name: name.into(), - type_params: type_params.iter().map(Into::into).collect(), + type_params: type_params.as_ref().map(Into::into), value: value.into(), }), ast::Stmt::Assign(ast::StmtAssign { diff --git a/crates/ruff_python_ast/src/helpers.rs b/crates/ruff_python_ast/src/helpers.rs index 038069c4a3..95b0d376c0 100644 --- a/crates/ruff_python_ast/src/helpers.rs +++ b/crates/ruff_python_ast/src/helpers.rs @@ -1,16 +1,17 @@ use std::borrow::Cow; use std::path::Path; +use num_traits::Zero; +use smallvec::SmallVec; + +use ruff_text_size::TextRange; + +use crate::call_path::CallPath; +use crate::statement_visitor::{walk_body, walk_stmt, StatementVisitor}; use crate::{ self as ast, Arguments, Constant, ExceptHandler, Expr, Keyword, MatchCase, Parameters, Pattern, Ranged, Stmt, TypeParam, }; -use num_traits::Zero; -use ruff_text_size::TextRange; -use smallvec::SmallVec; - -use crate::call_path::CallPath; -use crate::statement_visitor::{walk_body, walk_stmt, StatementVisitor}; /// Return `true` if the `Stmt` is a compound statement (as opposed to a simple statement). pub const fn is_compound_statement(stmt: &Stmt) -> bool { @@ -346,6 +347,7 @@ where match stmt { Stmt::FunctionDef(ast::StmtFunctionDef { parameters, + type_params, body, decorator_list, returns, @@ -353,6 +355,7 @@ where }) | Stmt::AsyncFunctionDef(ast::StmtAsyncFunctionDef { parameters, + type_params, body, decorator_list, returns, @@ -385,6 +388,11 @@ where .as_ref() .is_some_and(|expr| any_over_expr(expr, func)) }) + || type_params.as_ref().is_some_and(|type_params| { + type_params + .iter() + .any(|type_param| any_over_type_param(type_param, func)) + }) || body.iter().any(|stmt| any_over_stmt(stmt, func)) || decorator_list .iter() @@ -395,6 +403,7 @@ where } Stmt::ClassDef(ast::StmtClassDef { arguments, + type_params, body, decorator_list, .. @@ -407,6 +416,11 @@ where .iter() .any(|keyword| any_over_expr(&keyword.value, func)) }) + || type_params.as_ref().is_some_and(|type_params| { + type_params + .iter() + .any(|type_param| any_over_type_param(type_param, func)) + }) || body.iter().any(|stmt| any_over_stmt(stmt, func)) || decorator_list .iter() @@ -429,9 +443,11 @@ where .. }) => { any_over_expr(name, func) - || type_params - .iter() - .any(|type_param| any_over_type_param(type_param, func)) + || type_params.as_ref().is_some_and(|type_params| { + type_params + .iter() + .any(|type_param| any_over_type_param(type_param, func)) + }) || any_over_expr(value, func) } Stmt::Assign(ast::StmtAssign { targets, value, .. }) => { @@ -1271,13 +1287,13 @@ mod tests { use std::cell::RefCell; use std::vec; - use crate::{ - Constant, Expr, ExprConstant, ExprContext, ExprName, Identifier, Stmt, StmtTypeAlias, - TypeParam, TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, - }; use ruff_text_size::TextRange; use crate::helpers::{any_over_stmt, any_over_type_param, resolve_imported_module_path}; + use crate::{ + Constant, Expr, ExprConstant, ExprContext, ExprName, Identifier, Stmt, StmtTypeAlias, + TypeParam, TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, TypeParams, + }; #[test] fn resolve_import() { @@ -1351,7 +1367,10 @@ mod tests { }); let type_alias = Stmt::TypeAlias(StmtTypeAlias { name: Box::new(name.clone()), - type_params: vec![type_var_one, type_var_two], + type_params: Some(TypeParams { + type_params: vec![type_var_one, type_var_two], + range: TextRange::default(), + }), value: Box::new(constant_three.clone()), range: TextRange::default(), }); diff --git a/crates/ruff_python_ast/src/node.rs b/crates/ruff_python_ast/src/node.rs index 03329ff7b4..a3266e0e15 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, Arguments, Comprehension, Decorator, ExceptHandler, Expr, Keyword, MatchCase, Mod, Parameter, ParameterWithDefault, Parameters, Pattern, Ranged, Stmt, TypeParam, - TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, WithItem, + TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, TypeParams, WithItem, }; use ruff_text_size::TextRange; use std::ptr::NonNull; @@ -100,9 +100,10 @@ pub enum AnyNode { MatchCase(MatchCase), Decorator(Decorator), ElifElseClause(ast::ElifElseClause), - TypeParamTypeVar(ast::TypeParamTypeVar), - TypeParamTypeVarTuple(ast::TypeParamTypeVarTuple), - TypeParamParamSpec(ast::TypeParamParamSpec), + TypeParams(TypeParams), + TypeParamTypeVar(TypeParamTypeVar), + TypeParamTypeVarTuple(TypeParamTypeVarTuple), + TypeParamParamSpec(TypeParamParamSpec), } impl AnyNode { @@ -187,6 +188,7 @@ impl AnyNode { | AnyNode::WithItem(_) | AnyNode::MatchCase(_) | AnyNode::Decorator(_) + | AnyNode::TypeParams(_) | AnyNode::TypeParamTypeVar(_) | AnyNode::TypeParamTypeVarTuple(_) | AnyNode::TypeParamParamSpec(_) @@ -275,6 +277,7 @@ impl AnyNode { | AnyNode::WithItem(_) | AnyNode::MatchCase(_) | AnyNode::Decorator(_) + | AnyNode::TypeParams(_) | AnyNode::TypeParamTypeVar(_) | AnyNode::TypeParamTypeVarTuple(_) | AnyNode::TypeParamParamSpec(_) @@ -363,6 +366,7 @@ impl AnyNode { | AnyNode::WithItem(_) | AnyNode::MatchCase(_) | AnyNode::Decorator(_) + | AnyNode::TypeParams(_) | AnyNode::TypeParamTypeVar(_) | AnyNode::TypeParamTypeVarTuple(_) | AnyNode::TypeParamParamSpec(_) @@ -451,6 +455,7 @@ impl AnyNode { | AnyNode::WithItem(_) | AnyNode::MatchCase(_) | AnyNode::Decorator(_) + | AnyNode::TypeParams(_) | AnyNode::TypeParamTypeVar(_) | AnyNode::TypeParamTypeVarTuple(_) | AnyNode::TypeParamParamSpec(_) @@ -539,6 +544,7 @@ impl AnyNode { | AnyNode::WithItem(_) | AnyNode::MatchCase(_) | AnyNode::Decorator(_) + | AnyNode::TypeParams(_) | AnyNode::TypeParamTypeVar(_) | AnyNode::TypeParamTypeVarTuple(_) | AnyNode::TypeParamParamSpec(_) @@ -646,6 +652,7 @@ impl AnyNode { Self::WithItem(node) => AnyNodeRef::WithItem(node), Self::MatchCase(node) => AnyNodeRef::MatchCase(node), Self::Decorator(node) => AnyNodeRef::Decorator(node), + Self::TypeParams(node) => AnyNodeRef::TypeParams(node), Self::TypeParamTypeVar(node) => AnyNodeRef::TypeParamTypeVar(node), Self::TypeParamTypeVarTuple(node) => AnyNodeRef::TypeParamTypeVarTuple(node), Self::TypeParamParamSpec(node) => AnyNodeRef::TypeParamParamSpec(node), @@ -3590,6 +3597,7 @@ impl Ranged for AnyNode { AnyNode::WithItem(node) => node.range(), AnyNode::MatchCase(node) => node.range(), AnyNode::Decorator(node) => node.range(), + AnyNode::TypeParams(node) => node.range(), AnyNode::TypeParamTypeVar(node) => node.range(), AnyNode::TypeParamTypeVarTuple(node) => node.range(), AnyNode::TypeParamParamSpec(node) => node.range(), @@ -3678,9 +3686,10 @@ pub enum AnyNodeRef<'a> { WithItem(&'a WithItem), MatchCase(&'a MatchCase), Decorator(&'a Decorator), - TypeParamTypeVar(&'a ast::TypeParamTypeVar), - TypeParamTypeVarTuple(&'a ast::TypeParamTypeVarTuple), - TypeParamParamSpec(&'a ast::TypeParamParamSpec), + TypeParams(&'a TypeParams), + TypeParamTypeVar(&'a TypeParamTypeVar), + TypeParamTypeVarTuple(&'a TypeParamTypeVarTuple), + TypeParamParamSpec(&'a TypeParamParamSpec), ElifElseClause(&'a ast::ElifElseClause), } @@ -3765,6 +3774,7 @@ impl AnyNodeRef<'_> { AnyNodeRef::WithItem(node) => NonNull::from(*node).cast(), AnyNodeRef::MatchCase(node) => NonNull::from(*node).cast(), AnyNodeRef::Decorator(node) => NonNull::from(*node).cast(), + AnyNodeRef::TypeParams(node) => NonNull::from(*node).cast(), AnyNodeRef::TypeParamTypeVar(node) => NonNull::from(*node).cast(), AnyNodeRef::TypeParamTypeVarTuple(node) => NonNull::from(*node).cast(), AnyNodeRef::TypeParamParamSpec(node) => NonNull::from(*node).cast(), @@ -3858,6 +3868,7 @@ impl AnyNodeRef<'_> { AnyNodeRef::WithItem(_) => NodeKind::WithItem, AnyNodeRef::MatchCase(_) => NodeKind::MatchCase, AnyNodeRef::Decorator(_) => NodeKind::Decorator, + AnyNodeRef::TypeParams(_) => NodeKind::TypeParams, AnyNodeRef::TypeParamTypeVar(_) => NodeKind::TypeParamTypeVar, AnyNodeRef::TypeParamTypeVarTuple(_) => NodeKind::TypeParamTypeVarTuple, AnyNodeRef::TypeParamParamSpec(_) => NodeKind::TypeParamParamSpec, @@ -3946,6 +3957,7 @@ impl AnyNodeRef<'_> { | AnyNodeRef::WithItem(_) | AnyNodeRef::MatchCase(_) | AnyNodeRef::Decorator(_) + | AnyNodeRef::TypeParams(_) | AnyNodeRef::TypeParamTypeVar(_) | AnyNodeRef::TypeParamTypeVarTuple(_) | AnyNodeRef::TypeParamParamSpec(_) @@ -4034,6 +4046,7 @@ impl AnyNodeRef<'_> { | AnyNodeRef::WithItem(_) | AnyNodeRef::MatchCase(_) | AnyNodeRef::Decorator(_) + | AnyNodeRef::TypeParams(_) | AnyNodeRef::TypeParamTypeVar(_) | AnyNodeRef::TypeParamTypeVarTuple(_) | AnyNodeRef::TypeParamParamSpec(_) @@ -4121,6 +4134,7 @@ impl AnyNodeRef<'_> { | AnyNodeRef::WithItem(_) | AnyNodeRef::MatchCase(_) | AnyNodeRef::Decorator(_) + | AnyNodeRef::TypeParams(_) | AnyNodeRef::TypeParamTypeVar(_) | AnyNodeRef::TypeParamTypeVarTuple(_) | AnyNodeRef::TypeParamParamSpec(_) @@ -4209,6 +4223,7 @@ impl AnyNodeRef<'_> { | AnyNodeRef::WithItem(_) | AnyNodeRef::MatchCase(_) | AnyNodeRef::Decorator(_) + | AnyNodeRef::TypeParams(_) | AnyNodeRef::TypeParamTypeVar(_) | AnyNodeRef::TypeParamTypeVarTuple(_) | AnyNodeRef::TypeParamParamSpec(_) @@ -4297,6 +4312,7 @@ impl AnyNodeRef<'_> { | AnyNodeRef::WithItem(_) | AnyNodeRef::MatchCase(_) | AnyNodeRef::Decorator(_) + | AnyNodeRef::TypeParams(_) | AnyNodeRef::TypeParamTypeVar(_) | AnyNodeRef::TypeParamTypeVarTuple(_) | AnyNodeRef::TypeParamParamSpec(_) @@ -5011,6 +5027,7 @@ impl Ranged for AnyNodeRef<'_> { AnyNodeRef::MatchCase(node) => node.range(), AnyNodeRef::Decorator(node) => node.range(), AnyNodeRef::ElifElseClause(node) => node.range(), + AnyNodeRef::TypeParams(node) => node.range(), AnyNodeRef::TypeParamTypeVar(node) => node.range(), AnyNodeRef::TypeParamTypeVarTuple(node) => node.range(), AnyNodeRef::TypeParamParamSpec(node) => node.range(), @@ -5102,6 +5119,7 @@ pub enum NodeKind { MatchCase, Decorator, ElifElseClause, + TypeParams, TypeParamTypeVar, TypeParamTypeVarTuple, TypeParamParamSpec, diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 8a3ec1ae0f..9225728c2b 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -5,6 +5,7 @@ use num_bigint::BigInt; use ruff_text_size::{TextRange, TextSize}; use std::fmt; use std::fmt::Debug; +use std::ops::Deref; /// See also [mod](https://docs.python.org/3/library/ast.html#ast.mod) #[derive(Clone, Debug, PartialEq, is_macro::Is)] @@ -121,12 +122,12 @@ impl From for Stmt { #[derive(Clone, Debug, PartialEq)] pub struct StmtFunctionDef { pub range: TextRange, - pub name: Identifier, - pub parameters: Box, - pub body: Vec, pub decorator_list: Vec, + pub name: Identifier, + pub type_params: Option, + pub parameters: Box, pub returns: Option>, - pub type_params: Vec, + pub body: Vec, } impl From for Stmt { @@ -139,12 +140,12 @@ impl From for Stmt { #[derive(Clone, Debug, PartialEq)] pub struct StmtAsyncFunctionDef { pub range: TextRange, - pub name: Identifier, - pub parameters: Box, - pub body: Vec, pub decorator_list: Vec, + pub name: Identifier, + pub type_params: Option, + pub parameters: Box, pub returns: Option>, - pub type_params: Vec, + pub body: Vec, } impl From for Stmt { @@ -157,11 +158,11 @@ impl From for Stmt { #[derive(Clone, Debug, PartialEq)] pub struct StmtClassDef { pub range: TextRange, + pub decorator_list: Vec, pub name: Identifier, + pub type_params: Option, pub arguments: Option, pub body: Vec, - pub type_params: Vec, - pub decorator_list: Vec, } impl StmtClassDef { @@ -221,7 +222,7 @@ impl From for Stmt { pub struct StmtTypeAlias { pub range: TextRange, pub name: Box, - pub type_params: Vec, + pub type_params: Option, pub value: Box, } @@ -2120,6 +2121,29 @@ pub struct Arguments { pub keywords: Vec, } +/// An AST node used to represent a sequence of type parameters. +/// +/// For example, given: +/// ```python +/// class C[T, U, V]: ... +/// ``` +/// The `TypeParams` node would span from the left to right brackets (inclusive), and contain +/// the `T`, `U`, and `V` type parameters in the order they appear in the source code. + +#[derive(Clone, Debug, PartialEq)] +pub struct TypeParams { + pub range: TextRange, + pub type_params: Vec, +} + +impl Deref for TypeParams { + type Target = [TypeParam]; + + fn deref(&self) -> &Self::Target { + &self.type_params + } +} + pub type Suite = Vec; impl CmpOp { @@ -2952,6 +2976,11 @@ impl Ranged for crate::Pattern { } } +impl Ranged for crate::nodes::TypeParams { + fn range(&self) -> TextRange { + self.range + } +} impl Ranged for crate::nodes::TypeParamTypeVar { fn range(&self) -> TextRange { self.range @@ -3003,9 +3032,9 @@ mod size_assertions { use super::*; use static_assertions::assert_eq_size; - assert_eq_size!(Stmt, [u8; 176]); - assert_eq_size!(StmtFunctionDef, [u8; 128]); - assert_eq_size!(StmtClassDef, [u8; 168]); + assert_eq_size!(Stmt, [u8; 184]); + assert_eq_size!(StmtFunctionDef, [u8; 136]); + assert_eq_size!(StmtClassDef, [u8; 176]); assert_eq_size!(StmtTry, [u8; 104]); assert_eq_size!(Expr, [u8; 80]); assert_eq_size!(Constant, [u8; 32]); diff --git a/crates/ruff_python_ast/src/visitor.rs b/crates/ruff_python_ast/src/visitor.rs index fed8cb8140..f7ee69b9f8 100644 --- a/crates/ruff_python_ast/src/visitor.rs +++ b/crates/ruff_python_ast/src/visitor.rs @@ -5,7 +5,7 @@ pub mod preorder; use crate::{ self as ast, Alias, Arguments, BoolOp, CmpOp, Comprehension, Decorator, ElifElseClause, ExceptHandler, Expr, ExprContext, Keyword, MatchCase, Operator, Parameter, Parameters, Pattern, - Stmt, TypeParam, TypeParamTypeVar, UnaryOp, WithItem, + Stmt, TypeParam, TypeParamTypeVar, TypeParams, UnaryOp, WithItem, }; /// A trait for AST visitors. Visits all nodes in the AST recursively in evaluation-order. @@ -70,6 +70,9 @@ pub trait Visitor<'a> { fn visit_with_item(&mut self, with_item: &'a WithItem) { walk_with_item(self, with_item); } + fn visit_type_params(&mut self, type_params: &'a TypeParams) { + walk_type_params(self, type_params); + } fn visit_type_param(&mut self, type_param: &'a TypeParam) { walk_type_param(self, type_param); } @@ -116,8 +119,8 @@ pub fn walk_stmt<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, stmt: &'a Stmt) { for decorator in decorator_list { visitor.visit_decorator(decorator); } - for type_param in type_params { - visitor.visit_type_param(type_param); + if let Some(type_params) = type_params { + visitor.visit_type_params(type_params); } visitor.visit_parameters(parameters); for expr in returns { @@ -136,8 +139,8 @@ pub fn walk_stmt<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, stmt: &'a Stmt) { for decorator in decorator_list { visitor.visit_decorator(decorator); } - for type_param in type_params { - visitor.visit_type_param(type_param); + if let Some(type_params) = type_params { + visitor.visit_type_params(type_params); } visitor.visit_parameters(parameters); for expr in returns { @@ -155,8 +158,8 @@ pub fn walk_stmt<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, stmt: &'a Stmt) { for decorator in decorator_list { visitor.visit_decorator(decorator); } - for type_param in type_params { - visitor.visit_type_param(type_param); + if let Some(type_params) = type_params { + visitor.visit_type_params(type_params); } if let Some(arguments) = arguments { visitor.visit_arguments(arguments); @@ -186,8 +189,8 @@ pub fn walk_stmt<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, stmt: &'a Stmt) { value, }) => { visitor.visit_expr(value); - for type_param in type_params { - visitor.visit_type_param(type_param); + if let Some(type_params) = type_params { + visitor.visit_type_params(type_params); } visitor.visit_expr(name); } @@ -699,6 +702,12 @@ pub fn walk_with_item<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, with_item: & } } +pub fn walk_type_params<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, type_params: &'a TypeParams) { + for type_param in &type_params.type_params { + visitor.visit_type_param(type_param); + } +} + pub fn walk_type_param<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, type_param: &'a TypeParam) { match type_param { TypeParam::TypeVar(TypeParamTypeVar { diff --git a/crates/ruff_python_ast/src/visitor/preorder.rs b/crates/ruff_python_ast/src/visitor/preorder.rs index 35146041fe..d1eee2bcd0 100644 --- a/crates/ruff_python_ast/src/visitor/preorder.rs +++ b/crates/ruff_python_ast/src/visitor/preorder.rs @@ -1,8 +1,8 @@ use crate::{ self as ast, Alias, Arguments, BoolOp, CmpOp, Comprehension, Constant, Decorator, ElifElseClause, ExceptHandler, Expr, Keyword, MatchCase, Mod, Operator, Parameter, - ParameterWithDefault, Parameters, Pattern, Stmt, TypeParam, TypeParamTypeVar, UnaryOp, - WithItem, + ParameterWithDefault, Parameters, Pattern, Stmt, TypeParam, TypeParamTypeVar, TypeParams, + UnaryOp, WithItem, }; /// Visitor that traverses all nodes recursively in pre-order. @@ -85,6 +85,10 @@ pub trait PreorderVisitor<'a> { walk_with_item(self, with_item); } + fn visit_type_params(&mut self, type_params: &'a TypeParams) { + walk_type_params(self, type_params); + } + fn visit_type_param(&mut self, type_param: &'a TypeParam) { walk_type_param(self, type_param); } @@ -157,8 +161,8 @@ where visitor.visit_decorator(decorator); } - for type_param in type_params { - visitor.visit_type_param(type_param); + if let Some(type_params) = type_params { + visitor.visit_type_params(type_params); } visitor.visit_parameters(parameters); @@ -181,8 +185,8 @@ where visitor.visit_decorator(decorator); } - for type_param in type_params { - visitor.visit_type_param(type_param); + if let Some(type_params) = type_params { + visitor.visit_type_params(type_params); } if let Some(arguments) = arguments { @@ -217,8 +221,8 @@ where value, }) => { visitor.visit_expr(name); - for type_param in type_params { - visitor.visit_type_param(type_param); + if let Some(type_params) = type_params { + visitor.visit_type_params(type_params); } visitor.visit_expr(value); } @@ -817,6 +821,15 @@ where } } +pub fn walk_type_params<'a, V>(visitor: &mut V, type_params: &'a TypeParams) +where + V: PreorderVisitor<'a> + ?Sized, +{ + for type_param in &type_params.type_params { + visitor.visit_type_param(type_param); + } +} + pub fn walk_type_param<'a, V>(visitor: &mut V, type_param: &'a TypeParam) where V: PreorderVisitor<'a> + ?Sized, diff --git a/crates/ruff_python_codegen/src/generator.rs b/crates/ruff_python_codegen/src/generator.rs index 9178c98251..1e94200735 100644 --- a/crates/ruff_python_codegen/src/generator.rs +++ b/crates/ruff_python_codegen/src/generator.rs @@ -1,6 +1,6 @@ //! Generate Python source code from an abstract syntax tree (AST). -use ruff_python_ast::ParameterWithDefault; +use ruff_python_ast::{ParameterWithDefault, TypeParams}; use std::ops::Deref; use ruff_python_ast::{ @@ -222,7 +222,9 @@ impl<'a> Generator<'a> { statement!({ self.p("def "); self.p_id(name); - self.unparse_type_params(type_params); + if let Some(type_params) = type_params { + self.unparse_type_params(type_params); + } self.p("("); self.unparse_parameters(parameters); self.p(")"); @@ -256,7 +258,9 @@ impl<'a> Generator<'a> { statement!({ self.p("async def "); self.p_id(name); - self.unparse_type_params(type_params); + if let Some(type_params) = type_params { + self.unparse_type_params(type_params); + } self.p("("); self.unparse_parameters(parameters); self.p(")"); @@ -289,7 +293,9 @@ impl<'a> Generator<'a> { statement!({ self.p("class "); self.p_id(name); - self.unparse_type_params(type_params); + if let Some(type_params) = type_params { + self.unparse_type_params(type_params); + } if let Some(arguments) = arguments { self.p("("); let mut first = true; @@ -540,7 +546,9 @@ impl<'a> Generator<'a> { }) => { self.p("type "); self.unparse_expr(name, precedence::MAX); - self.unparse_type_params(type_params); + if let Some(type_params) = type_params { + self.unparse_type_params(type_params); + } self.p(" = "); self.unparse_expr(value, precedence::ASSIGN); } @@ -853,16 +861,14 @@ impl<'a> Generator<'a> { self.body(&ast.body); } - fn unparse_type_params(&mut self, type_params: &Vec) { - if !type_params.is_empty() { - self.p("["); - let mut first = true; - for type_param in type_params { - self.p_delim(&mut first, ", "); - self.unparse_type_param(type_param); - } - self.p("]"); + fn unparse_type_params(&mut self, type_params: &TypeParams) { + self.p("["); + let mut first = true; + for type_param in type_params.iter() { + self.p_delim(&mut first, ", "); + self.unparse_type_param(type_param); } + self.p("]"); } pub(crate) fn unparse_type_param(&mut self, ast: &TypeParam) { diff --git a/crates/ruff_python_parser/src/python.lalrpop b/crates/ruff_python_parser/src/python.lalrpop index e10a09fd76..6e6869b1c6 100644 --- a/crates/ruff_python_parser/src/python.lalrpop +++ b/crates/ruff_python_parser/src/python.lalrpop @@ -1010,14 +1010,14 @@ WithItem: ast::WithItem = { }; FuncDef: ast::Stmt = { - "def" " >)?> ":" => { + "def" " >)?> ":" => { let args = Box::new(args); let returns = r.map(Box::new); let end_location = body.last().unwrap().end(); if is_async.is_some() { - ast::StmtAsyncFunctionDef { name, parameters:args, body, decorator_list, returns, type_params: type_params.unwrap_or_default(), range: (location..end_location).into() }.into() + ast::StmtAsyncFunctionDef { name, parameters:args, body, decorator_list, returns, type_params, range: (location..end_location).into() }.into() } else { - ast::StmtFunctionDef { name, parameters:args, body, decorator_list, returns, type_params: type_params.unwrap_or_default(), range: (location..end_location).into() }.into() + ast::StmtFunctionDef { name, parameters:args, body, decorator_list, returns, type_params, range: (location..end_location).into() }.into() } }, }; @@ -1029,12 +1029,12 @@ TypeAliasName: ast::Expr = { } TypeAliasStatement: ast::Stmt = { - "type" "=" > => { + "type" "=" > => { ast::Stmt::TypeAlias( ast::StmtTypeAlias { name: Box::new(name), value: Box::new(value), - type_params: type_params.unwrap_or_default(), + type_params, range: (location..end_location).into() }, ) @@ -1194,7 +1194,7 @@ KwargParameter: Option> = { }; ClassDef: ast::Stmt = { - "class" ":" => { + "class" ":" => { let end_location = body.last().unwrap().end(); ast::Stmt::ClassDef( ast::StmtClassDef { @@ -1202,17 +1202,19 @@ ClassDef: ast::Stmt = { arguments, body, decorator_list, - type_params: type_params.unwrap_or_default(), + type_params, range: (location..end_location).into() }, ) }, }; - -TypeParamList: Vec = { +TypeParams: ast::TypeParams = { "[" > ","? "]" => { - vars + ast::TypeParams { + type_params: vars, + range: (location..end_location).into() + } } }; diff --git a/crates/ruff_python_parser/src/python.rs b/crates/ruff_python_parser/src/python.rs index fc890e743f..f01da55f4f 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: 3c5459b3b4420f13663b68f1bf78d526b5e5b0249d7877fe70dad50319098ef9 +// sha3: aadf067e37a9f39d450f1403b759a9659c60e697758ddd2b8c2b5fa2d0d73672 use num_bigint::BigInt; use ruff_text_size::TextSize; use ruff_python_ast::{self as ast, Ranged, MagicKind}; @@ -134,8 +134,9 @@ mod __parse__Top { Variant88(Vec), Variant89(ast::Mod), Variant90(ast::TypeParam), - Variant91(core::option::Option>), - Variant92(ast::UnaryOp), + Variant91(ast::TypeParams), + Variant92(core::option::Option), + Variant93(ast::UnaryOp), } const __ACTION: &[i16] = &[ // State 0 @@ -18269,13 +18270,23 @@ mod __parse__Top { _ => __symbol_type_mismatch() } } - fn __pop_Variant92< + fn __pop_Variant91< + >( + __symbols: &mut alloc::vec::Vec<(TextSize,__Symbol<>,TextSize)> + ) -> (TextSize, ast::TypeParams, TextSize) + { + match __symbols.pop() { + Some((__l, __Symbol::Variant91(__v), __r)) => (__l, __v, __r), + _ => __symbol_type_mismatch() + } + } + fn __pop_Variant93< >( __symbols: &mut alloc::vec::Vec<(TextSize,__Symbol<>,TextSize)> ) -> (TextSize, ast::UnaryOp, TextSize) { match __symbols.pop() { - Some((__l, __Symbol::Variant92(__v), __r)) => (__l, __v, __r), + Some((__l, __Symbol::Variant93(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } @@ -18369,16 +18380,6 @@ mod __parse__Top { _ => __symbol_type_mismatch() } } - fn __pop_Variant91< - >( - __symbols: &mut alloc::vec::Vec<(TextSize,__Symbol<>,TextSize)> - ) -> (TextSize, core::option::Option>, TextSize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant91(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } fn __pop_Variant40< >( __symbols: &mut alloc::vec::Vec<(TextSize,__Symbol<>,TextSize)> @@ -18459,6 +18460,16 @@ mod __parse__Top { _ => __symbol_type_mismatch() } } + fn __pop_Variant92< + >( + __symbols: &mut alloc::vec::Vec<(TextSize,__Symbol<>,TextSize)> + ) -> (TextSize, core::option::Option, TextSize) + { + match __symbols.pop() { + Some((__l, __Symbol::Variant92(__v), __r)) => (__l, __v, __r), + _ => __symbol_type_mismatch() + } + } fn __pop_Variant7< >( __symbols: &mut alloc::vec::Vec<(TextSize,__Symbol<>,TextSize)> @@ -22026,12 +22037,12 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // ClassDef = "class", Identifier, TypeParamList, Arguments, ":", Suite => ActionFn(1712); + // ClassDef = "class", Identifier, TypeParams, Arguments, ":", Suite => ActionFn(1712); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant24(__symbols); let __sym4 = __pop_Variant0(__symbols); let __sym3 = __pop_Variant49(__symbols); - let __sym2 = __pop_Variant81(__symbols); + let __sym2 = __pop_Variant91(__symbols); let __sym1 = __pop_Variant22(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0; @@ -22069,12 +22080,12 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // ClassDef = Decorator+, "class", Identifier, TypeParamList, Arguments, ":", Suite => ActionFn(1714); + // ClassDef = Decorator+, "class", Identifier, TypeParams, Arguments, ":", Suite => ActionFn(1714); assert!(__symbols.len() >= 7); let __sym6 = __pop_Variant24(__symbols); let __sym5 = __pop_Variant0(__symbols); let __sym4 = __pop_Variant49(__symbols); - let __sym3 = __pop_Variant81(__symbols); + let __sym3 = __pop_Variant91(__symbols); let __sym2 = __pop_Variant22(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant58(__symbols); @@ -22114,11 +22125,11 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // ClassDef = "class", Identifier, TypeParamList, ":", Suite => ActionFn(1716); + // ClassDef = "class", Identifier, TypeParams, ":", Suite => ActionFn(1716); assert!(__symbols.len() >= 5); let __sym4 = __pop_Variant24(__symbols); let __sym3 = __pop_Variant0(__symbols); - let __sym2 = __pop_Variant81(__symbols); + let __sym2 = __pop_Variant91(__symbols); let __sym1 = __pop_Variant22(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0; @@ -22155,11 +22166,11 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // ClassDef = Decorator+, "class", Identifier, TypeParamList, ":", Suite => ActionFn(1718); + // ClassDef = Decorator+, "class", Identifier, TypeParams, ":", Suite => ActionFn(1718); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant24(__symbols); let __sym4 = __pop_Variant0(__symbols); - let __sym3 = __pop_Variant81(__symbols); + let __sym3 = __pop_Variant91(__symbols); let __sym2 = __pop_Variant22(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant58(__symbols); @@ -24076,7 +24087,7 @@ mod __parse__Top { // Factor<"all"> = UnaryOp, Factor<"all"> => ActionFn(1278); assert!(__symbols.len() >= 2); let __sym1 = __pop_Variant14(__symbols); - let __sym0 = __pop_Variant92(__symbols); + let __sym0 = __pop_Variant93(__symbols); let __start = __sym0.0; let __end = __sym1.2; let __nt = super::__action1278::<>(mode, __sym0, __sym1); @@ -24110,7 +24121,7 @@ mod __parse__Top { // Factor<"no-withitems"> = UnaryOp, Factor<"all"> => ActionFn(1279); assert!(__symbols.len() >= 2); let __sym1 = __pop_Variant14(__symbols); - let __sym0 = __pop_Variant92(__symbols); + let __sym0 = __pop_Variant93(__symbols); let __start = __sym0.0; let __end = __sym1.2; let __nt = super::__action1279::<>(mode, __sym0, __sym1); @@ -24335,14 +24346,14 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // FuncDef = "async", "def", Identifier, TypeParamList, Parameters, "->", Test<"all">, ":", Suite => ActionFn(1720); + // FuncDef = "async", "def", Identifier, TypeParams, Parameters, "->", Test<"all">, ":", Suite => ActionFn(1720); assert!(__symbols.len() >= 9); let __sym8 = __pop_Variant24(__symbols); let __sym7 = __pop_Variant0(__symbols); let __sym6 = __pop_Variant14(__symbols); let __sym5 = __pop_Variant0(__symbols); let __sym4 = __pop_Variant45(__symbols); - let __sym3 = __pop_Variant81(__symbols); + let __sym3 = __pop_Variant91(__symbols); let __sym2 = __pop_Variant22(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); @@ -24384,14 +24395,14 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // FuncDef = Decorator+, "async", "def", Identifier, TypeParamList, Parameters, "->", Test<"all">, ":", Suite => ActionFn(1722); + // FuncDef = Decorator+, "async", "def", Identifier, TypeParams, Parameters, "->", Test<"all">, ":", Suite => ActionFn(1722); assert!(__symbols.len() >= 10); let __sym9 = __pop_Variant24(__symbols); let __sym8 = __pop_Variant0(__symbols); let __sym7 = __pop_Variant14(__symbols); let __sym6 = __pop_Variant0(__symbols); let __sym5 = __pop_Variant45(__symbols); - let __sym4 = __pop_Variant81(__symbols); + let __sym4 = __pop_Variant91(__symbols); let __sym3 = __pop_Variant22(__symbols); let __sym2 = __pop_Variant0(__symbols); let __sym1 = __pop_Variant0(__symbols); @@ -24435,12 +24446,12 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // FuncDef = "async", "def", Identifier, TypeParamList, Parameters, ":", Suite => ActionFn(1724); + // FuncDef = "async", "def", Identifier, TypeParams, Parameters, ":", Suite => ActionFn(1724); assert!(__symbols.len() >= 7); let __sym6 = __pop_Variant24(__symbols); let __sym5 = __pop_Variant0(__symbols); let __sym4 = __pop_Variant45(__symbols); - let __sym3 = __pop_Variant81(__symbols); + let __sym3 = __pop_Variant91(__symbols); let __sym2 = __pop_Variant22(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); @@ -24480,12 +24491,12 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // FuncDef = Decorator+, "async", "def", Identifier, TypeParamList, Parameters, ":", Suite => ActionFn(1726); + // FuncDef = Decorator+, "async", "def", Identifier, TypeParams, Parameters, ":", Suite => ActionFn(1726); assert!(__symbols.len() >= 8); let __sym7 = __pop_Variant24(__symbols); let __sym6 = __pop_Variant0(__symbols); let __sym5 = __pop_Variant45(__symbols); - let __sym4 = __pop_Variant81(__symbols); + let __sym4 = __pop_Variant91(__symbols); let __sym3 = __pop_Variant22(__symbols); let __sym2 = __pop_Variant0(__symbols); let __sym1 = __pop_Variant0(__symbols); @@ -24527,14 +24538,14 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // FuncDef = "def", Identifier, TypeParamList, Parameters, "->", Test<"all">, ":", Suite => ActionFn(1728); + // FuncDef = "def", Identifier, TypeParams, Parameters, "->", Test<"all">, ":", Suite => ActionFn(1728); assert!(__symbols.len() >= 8); let __sym7 = __pop_Variant24(__symbols); let __sym6 = __pop_Variant0(__symbols); let __sym5 = __pop_Variant14(__symbols); let __sym4 = __pop_Variant0(__symbols); let __sym3 = __pop_Variant45(__symbols); - let __sym2 = __pop_Variant81(__symbols); + let __sym2 = __pop_Variant91(__symbols); let __sym1 = __pop_Variant22(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0; @@ -24574,14 +24585,14 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // FuncDef = Decorator+, "def", Identifier, TypeParamList, Parameters, "->", Test<"all">, ":", Suite => ActionFn(1730); + // FuncDef = Decorator+, "def", Identifier, TypeParams, Parameters, "->", Test<"all">, ":", Suite => ActionFn(1730); assert!(__symbols.len() >= 9); let __sym8 = __pop_Variant24(__symbols); let __sym7 = __pop_Variant0(__symbols); let __sym6 = __pop_Variant14(__symbols); let __sym5 = __pop_Variant0(__symbols); let __sym4 = __pop_Variant45(__symbols); - let __sym3 = __pop_Variant81(__symbols); + let __sym3 = __pop_Variant91(__symbols); let __sym2 = __pop_Variant22(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant58(__symbols); @@ -24623,12 +24634,12 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // FuncDef = "def", Identifier, TypeParamList, Parameters, ":", Suite => ActionFn(1732); + // FuncDef = "def", Identifier, TypeParams, Parameters, ":", Suite => ActionFn(1732); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant24(__symbols); let __sym4 = __pop_Variant0(__symbols); let __sym3 = __pop_Variant45(__symbols); - let __sym2 = __pop_Variant81(__symbols); + let __sym2 = __pop_Variant91(__symbols); let __sym1 = __pop_Variant22(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0; @@ -24666,12 +24677,12 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // FuncDef = Decorator+, "def", Identifier, TypeParamList, Parameters, ":", Suite => ActionFn(1734); + // FuncDef = Decorator+, "def", Identifier, TypeParams, Parameters, ":", Suite => ActionFn(1734); assert!(__symbols.len() >= 7); let __sym6 = __pop_Variant24(__symbols); let __sym5 = __pop_Variant0(__symbols); let __sym4 = __pop_Variant45(__symbols); - let __sym3 = __pop_Variant81(__symbols); + let __sym3 = __pop_Variant91(__symbols); let __sym2 = __pop_Variant22(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant58(__symbols); @@ -29792,11 +29803,11 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // TypeAliasStatement = "type", TypeAliasName, TypeParamList, "=", Test<"all"> => ActionFn(1736); + // TypeAliasStatement = "type", TypeAliasName, TypeParams, "=", Test<"all"> => ActionFn(1736); assert!(__symbols.len() >= 5); let __sym4 = __pop_Variant14(__symbols); let __sym3 = __pop_Variant0(__symbols); - let __sym2 = __pop_Variant81(__symbols); + let __sym2 = __pop_Variant91(__symbols); let __sym1 = __pop_Variant14(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0; @@ -29904,7 +29915,7 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // TypeParamList = "[", OneOrMore, ",", "]" => ActionFn(1462); + // TypeParams = "[", OneOrMore, ",", "]" => ActionFn(1462); assert!(__symbols.len() >= 4); let __sym3 = __pop_Variant0(__symbols); let __sym2 = __pop_Variant0(__symbols); @@ -29913,7 +29924,7 @@ mod __parse__Top { let __start = __sym0.0; let __end = __sym3.2; let __nt = super::__action1462::<>(mode, __sym0, __sym1, __sym2, __sym3); - __symbols.push((__start, __Symbol::Variant81(__nt), __end)); + __symbols.push((__start, __Symbol::Variant91(__nt), __end)); (4, 260) } pub(crate) fn __reduce876< @@ -29924,7 +29935,7 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // TypeParamList = "[", OneOrMore, "]" => ActionFn(1463); + // TypeParams = "[", OneOrMore, "]" => ActionFn(1463); assert!(__symbols.len() >= 3); let __sym2 = __pop_Variant0(__symbols); let __sym1 = __pop_Variant81(__symbols); @@ -29932,7 +29943,7 @@ mod __parse__Top { let __start = __sym0.0; let __end = __sym2.2; let __nt = super::__action1463::<>(mode, __sym0, __sym1, __sym2); - __symbols.push((__start, __Symbol::Variant81(__nt), __end)); + __symbols.push((__start, __Symbol::Variant91(__nt), __end)); (3, 260) } pub(crate) fn __reduce877< @@ -29943,12 +29954,12 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // TypeParamList? = TypeParamList => ActionFn(284); - let __sym0 = __pop_Variant81(__symbols); + // TypeParams? = TypeParams => ActionFn(284); + let __sym0 = __pop_Variant91(__symbols); let __start = __sym0.0; let __end = __sym0.2; let __nt = super::__action284::<>(mode, __sym0); - __symbols.push((__start, __Symbol::Variant91(__nt), __end)); + __symbols.push((__start, __Symbol::Variant92(__nt), __end)); (1, 261) } pub(crate) fn __reduce878< @@ -29959,11 +29970,11 @@ mod __parse__Top { _: core::marker::PhantomData<()>, ) -> (usize, usize) { - // TypeParamList? = => ActionFn(285); + // TypeParams? = => ActionFn(285); let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); let __end = __start.clone(); let __nt = super::__action285::<>(mode, &__start, &__end); - __symbols.push((__start, __Symbol::Variant91(__nt), __end)); + __symbols.push((__start, __Symbol::Variant92(__nt), __end)); (0, 261) } pub(crate) fn __reduce879< @@ -30014,7 +30025,7 @@ mod __parse__Top { let __start = __sym0.0; let __end = __sym0.2; let __nt = super::__action201::<>(mode, __sym0); - __symbols.push((__start, __Symbol::Variant92(__nt), __end)); + __symbols.push((__start, __Symbol::Variant93(__nt), __end)); (1, 263) } pub(crate) fn __reduce882< @@ -30030,7 +30041,7 @@ mod __parse__Top { let __start = __sym0.0; let __end = __sym0.2; let __nt = super::__action202::<>(mode, __sym0); - __symbols.push((__start, __Symbol::Variant92(__nt), __end)); + __symbols.push((__start, __Symbol::Variant93(__nt), __end)); (1, 263) } pub(crate) fn __reduce883< @@ -30046,7 +30057,7 @@ mod __parse__Top { let __start = __sym0.0; let __end = __sym0.2; let __nt = super::__action203::<>(mode, __sym0); - __symbols.push((__start, __Symbol::Variant92(__nt), __end)); + __symbols.push((__start, __Symbol::Variant93(__nt), __end)); (1, 263) } pub(crate) fn __reduce884< @@ -33385,7 +33396,7 @@ fn __action161< (_, is_async, _): (TextSize, core::option::Option, TextSize), (_, _, _): (TextSize, token::Tok, TextSize), (_, name, _): (TextSize, ast::Identifier, TextSize), - (_, type_params, _): (TextSize, core::option::Option>, TextSize), + (_, type_params, _): (TextSize, core::option::Option, TextSize), (_, args, _): (TextSize, ast::Parameters, TextSize), (_, r, _): (TextSize, core::option::Option, TextSize), (_, _, _): (TextSize, token::Tok, TextSize), @@ -33397,9 +33408,9 @@ fn __action161< let returns = r.map(Box::new); let end_location = body.last().unwrap().end(); if is_async.is_some() { - ast::StmtAsyncFunctionDef { name, parameters:args, body, decorator_list, returns, type_params: type_params.unwrap_or_default(), range: (location..end_location).into() }.into() + ast::StmtAsyncFunctionDef { name, parameters:args, body, decorator_list, returns, type_params, range: (location..end_location).into() }.into() } else { - ast::StmtFunctionDef { name, parameters:args, body, decorator_list, returns, type_params: type_params.unwrap_or_default(), range: (location..end_location).into() }.into() + ast::StmtFunctionDef { name, parameters:args, body, decorator_list, returns, type_params, range: (location..end_location).into() }.into() } } } @@ -33427,7 +33438,7 @@ fn __action163< (_, location, _): (TextSize, TextSize, TextSize), (_, _, _): (TextSize, token::Tok, TextSize), (_, name, _): (TextSize, ast::Expr, TextSize), - (_, type_params, _): (TextSize, core::option::Option>, TextSize), + (_, type_params, _): (TextSize, core::option::Option, TextSize), (_, _, _): (TextSize, token::Tok, TextSize), (_, value, _): (TextSize, ast::Expr, TextSize), (_, end_location, _): (TextSize, TextSize, TextSize), @@ -33438,7 +33449,7 @@ fn __action163< ast::StmtTypeAlias { name: Box::new(name), value: Box::new(value), - type_params: type_params.unwrap_or_default(), + type_params, range: (location..end_location).into() }, ) @@ -33561,7 +33572,7 @@ fn __action170< (_, decorator_list, _): (TextSize, alloc::vec::Vec, TextSize), (_, _, _): (TextSize, token::Tok, TextSize), (_, name, _): (TextSize, ast::Identifier, TextSize), - (_, type_params, _): (TextSize, core::option::Option>, TextSize), + (_, type_params, _): (TextSize, core::option::Option, TextSize), (_, arguments, _): (TextSize, core::option::Option, TextSize), (_, _, _): (TextSize, token::Tok, TextSize), (_, body, _): (TextSize, ast::Suite, TextSize), @@ -33575,7 +33586,7 @@ fn __action170< arguments, body, decorator_list, - type_params: type_params.unwrap_or_default(), + type_params, range: (location..end_location).into() }, ) @@ -33593,10 +33604,13 @@ fn __action171< (_, _, _): (TextSize, core::option::Option, TextSize), (_, _, _): (TextSize, token::Tok, TextSize), (_, end_location, _): (TextSize, TextSize, TextSize), -) -> Vec +) -> ast::TypeParams { { - vars + ast::TypeParams { + type_params: vars, + range: (location..end_location).into() + } } } @@ -35226,8 +35240,8 @@ fn __action283< fn __action284< >( mode: Mode, - (_, __0, _): (TextSize, Vec, TextSize), -) -> core::option::Option> + (_, __0, _): (TextSize, ast::TypeParams, TextSize), +) -> core::option::Option { Some(__0) } @@ -35239,7 +35253,7 @@ fn __action285< mode: Mode, __lookbehind: &TextSize, __lookahead: &TextSize, -) -> core::option::Option> +) -> core::option::Option { None } @@ -41093,7 +41107,7 @@ fn __action641< __3: (TextSize, token::Tok, TextSize), __4: (TextSize, token::Tok, TextSize), __5: (TextSize, TextSize, TextSize), -) -> Vec +) -> ast::TypeParams { let __start0 = __3.0; let __end0 = __3.2; @@ -41123,7 +41137,7 @@ fn __action642< __2: (TextSize, Vec, TextSize), __3: (TextSize, token::Tok, TextSize), __4: (TextSize, TextSize, TextSize), -) -> Vec +) -> ast::TypeParams { let __start0 = __2.2; let __end0 = __3.0; @@ -41568,7 +41582,7 @@ fn __action657< __2: (TextSize, token::Tok, TextSize), __3: (TextSize, token::Tok, TextSize), __4: (TextSize, ast::Identifier, TextSize), - __5: (TextSize, core::option::Option>, TextSize), + __5: (TextSize, core::option::Option, TextSize), __6: (TextSize, ast::Parameters, TextSize), __7: (TextSize, core::option::Option, TextSize), __8: (TextSize, token::Tok, TextSize), @@ -41606,7 +41620,7 @@ fn __action658< __1: (TextSize, alloc::vec::Vec, TextSize), __2: (TextSize, token::Tok, TextSize), __3: (TextSize, ast::Identifier, TextSize), - __4: (TextSize, core::option::Option>, TextSize), + __4: (TextSize, core::option::Option, TextSize), __5: (TextSize, ast::Parameters, TextSize), __6: (TextSize, core::option::Option, TextSize), __7: (TextSize, token::Tok, TextSize), @@ -44422,7 +44436,7 @@ fn __action757< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, core::option::Option>, TextSize), + __3: (TextSize, core::option::Option, TextSize), __4: (TextSize, core::option::Option, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Suite, TextSize), @@ -45650,7 +45664,7 @@ fn __action798< __1: (TextSize, token::Tok, TextSize), __2: (TextSize, token::Tok, TextSize), __3: (TextSize, ast::Identifier, TextSize), - __4: (TextSize, core::option::Option>, TextSize), + __4: (TextSize, core::option::Option, TextSize), __5: (TextSize, ast::Parameters, TextSize), __6: (TextSize, core::option::Option, TextSize), __7: (TextSize, token::Tok, TextSize), @@ -45688,7 +45702,7 @@ fn __action799< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, core::option::Option>, TextSize), + __3: (TextSize, core::option::Option, TextSize), __4: (TextSize, ast::Parameters, TextSize), __5: (TextSize, core::option::Option, TextSize), __6: (TextSize, token::Tok, TextSize), @@ -49144,7 +49158,7 @@ fn __action921< mode: Mode, __0: (TextSize, token::Tok, TextSize), __1: (TextSize, ast::Expr, TextSize), - __2: (TextSize, core::option::Option>, TextSize), + __2: (TextSize, core::option::Option, TextSize), __3: (TextSize, token::Tok, TextSize), __4: (TextSize, ast::Expr, TextSize), __5: (TextSize, TextSize, TextSize), @@ -49261,7 +49275,7 @@ fn __action925< __2: (TextSize, token::Tok, TextSize), __3: (TextSize, token::Tok, TextSize), __4: (TextSize, TextSize, TextSize), -) -> Vec +) -> ast::TypeParams { let __start0 = __0.0; let __end0 = __0.0; @@ -49291,7 +49305,7 @@ fn __action926< __1: (TextSize, Vec, TextSize), __2: (TextSize, token::Tok, TextSize), __3: (TextSize, TextSize, TextSize), -) -> Vec +) -> ast::TypeParams { let __start0 = __0.0; let __end0 = __0.0; @@ -53480,7 +53494,7 @@ fn __action1073< __1: (TextSize, token::Tok, TextSize), __2: (TextSize, token::Tok, TextSize), __3: (TextSize, ast::Identifier, TextSize), - __4: (TextSize, core::option::Option>, TextSize), + __4: (TextSize, core::option::Option, TextSize), __5: (TextSize, ast::Parameters, TextSize), __6: (TextSize, token::Tok, TextSize), __7: (TextSize, ast::Expr, TextSize), @@ -53519,7 +53533,7 @@ fn __action1074< __1: (TextSize, token::Tok, TextSize), __2: (TextSize, token::Tok, TextSize), __3: (TextSize, ast::Identifier, TextSize), - __4: (TextSize, core::option::Option>, TextSize), + __4: (TextSize, core::option::Option, TextSize), __5: (TextSize, ast::Parameters, TextSize), __6: (TextSize, token::Tok, TextSize), __7: (TextSize, ast::Suite, TextSize), @@ -53555,7 +53569,7 @@ fn __action1075< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, core::option::Option>, TextSize), + __3: (TextSize, core::option::Option, TextSize), __4: (TextSize, ast::Parameters, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Expr, TextSize), @@ -53592,7 +53606,7 @@ fn __action1076< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, core::option::Option>, TextSize), + __3: (TextSize, core::option::Option, TextSize), __4: (TextSize, ast::Parameters, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Suite, TextSize), @@ -64235,7 +64249,7 @@ fn __action1457< mode: Mode, __0: (TextSize, token::Tok, TextSize), __1: (TextSize, ast::Expr, TextSize), - __2: (TextSize, core::option::Option>, TextSize), + __2: (TextSize, core::option::Option, TextSize), __3: (TextSize, token::Tok, TextSize), __4: (TextSize, ast::Expr, TextSize), ) -> ast::Stmt @@ -64368,7 +64382,7 @@ fn __action1462< __1: (TextSize, Vec, TextSize), __2: (TextSize, token::Tok, TextSize), __3: (TextSize, token::Tok, TextSize), -) -> Vec +) -> ast::TypeParams { let __start0 = __3.2; let __end0 = __3.2; @@ -64396,7 +64410,7 @@ fn __action1463< __0: (TextSize, token::Tok, TextSize), __1: (TextSize, Vec, TextSize), __2: (TextSize, token::Tok, TextSize), -) -> Vec +) -> ast::TypeParams { let __start0 = __2.2; let __end0 = __2.2; @@ -65355,7 +65369,7 @@ fn __action1500< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, core::option::Option>, TextSize), + __3: (TextSize, core::option::Option, TextSize), __4: (TextSize, ast::Arguments, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Suite, TextSize), @@ -65388,7 +65402,7 @@ fn __action1501< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, core::option::Option>, TextSize), + __3: (TextSize, core::option::Option, TextSize), __4: (TextSize, token::Tok, TextSize), __5: (TextSize, ast::Suite, TextSize), ) -> ast::Stmt @@ -66070,7 +66084,7 @@ fn __action1528< mode: Mode, __0: (TextSize, token::Tok, TextSize), __1: (TextSize, ast::Identifier, TextSize), - __2: (TextSize, core::option::Option>, TextSize), + __2: (TextSize, core::option::Option, TextSize), __3: (TextSize, ast::Arguments, TextSize), __4: (TextSize, token::Tok, TextSize), __5: (TextSize, ast::Suite, TextSize), @@ -66104,7 +66118,7 @@ fn __action1529< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, core::option::Option>, TextSize), + __3: (TextSize, core::option::Option, TextSize), __4: (TextSize, ast::Arguments, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Suite, TextSize), @@ -66136,7 +66150,7 @@ fn __action1530< mode: Mode, __0: (TextSize, token::Tok, TextSize), __1: (TextSize, ast::Identifier, TextSize), - __2: (TextSize, core::option::Option>, TextSize), + __2: (TextSize, core::option::Option, TextSize), __3: (TextSize, token::Tok, TextSize), __4: (TextSize, ast::Suite, TextSize), ) -> ast::Stmt @@ -66168,7 +66182,7 @@ fn __action1531< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, core::option::Option>, TextSize), + __3: (TextSize, core::option::Option, TextSize), __4: (TextSize, token::Tok, TextSize), __5: (TextSize, ast::Suite, TextSize), ) -> ast::Stmt @@ -66199,7 +66213,7 @@ fn __action1532< __0: (TextSize, token::Tok, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, core::option::Option>, TextSize), + __3: (TextSize, core::option::Option, TextSize), __4: (TextSize, ast::Parameters, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Expr, TextSize), @@ -66239,7 +66253,7 @@ fn __action1533< __1: (TextSize, token::Tok, TextSize), __2: (TextSize, token::Tok, TextSize), __3: (TextSize, ast::Identifier, TextSize), - __4: (TextSize, core::option::Option>, TextSize), + __4: (TextSize, core::option::Option, TextSize), __5: (TextSize, ast::Parameters, TextSize), __6: (TextSize, token::Tok, TextSize), __7: (TextSize, ast::Expr, TextSize), @@ -66277,7 +66291,7 @@ fn __action1534< __0: (TextSize, token::Tok, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, core::option::Option>, TextSize), + __3: (TextSize, core::option::Option, TextSize), __4: (TextSize, ast::Parameters, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Suite, TextSize), @@ -66313,7 +66327,7 @@ fn __action1535< __1: (TextSize, token::Tok, TextSize), __2: (TextSize, token::Tok, TextSize), __3: (TextSize, ast::Identifier, TextSize), - __4: (TextSize, core::option::Option>, TextSize), + __4: (TextSize, core::option::Option, TextSize), __5: (TextSize, ast::Parameters, TextSize), __6: (TextSize, token::Tok, TextSize), __7: (TextSize, ast::Suite, TextSize), @@ -66346,7 +66360,7 @@ fn __action1536< mode: Mode, __0: (TextSize, token::Tok, TextSize), __1: (TextSize, ast::Identifier, TextSize), - __2: (TextSize, core::option::Option>, TextSize), + __2: (TextSize, core::option::Option, TextSize), __3: (TextSize, ast::Parameters, TextSize), __4: (TextSize, token::Tok, TextSize), __5: (TextSize, ast::Expr, TextSize), @@ -66384,7 +66398,7 @@ fn __action1537< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, core::option::Option>, TextSize), + __3: (TextSize, core::option::Option, TextSize), __4: (TextSize, ast::Parameters, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Expr, TextSize), @@ -66420,7 +66434,7 @@ fn __action1538< mode: Mode, __0: (TextSize, token::Tok, TextSize), __1: (TextSize, ast::Identifier, TextSize), - __2: (TextSize, core::option::Option>, TextSize), + __2: (TextSize, core::option::Option, TextSize), __3: (TextSize, ast::Parameters, TextSize), __4: (TextSize, token::Tok, TextSize), __5: (TextSize, ast::Suite, TextSize), @@ -66454,7 +66468,7 @@ fn __action1539< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, core::option::Option>, TextSize), + __3: (TextSize, core::option::Option, TextSize), __4: (TextSize, ast::Parameters, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Suite, TextSize), @@ -71718,7 +71732,7 @@ fn __action1712< mode: Mode, __0: (TextSize, token::Tok, TextSize), __1: (TextSize, ast::Identifier, TextSize), - __2: (TextSize, Vec, TextSize), + __2: (TextSize, ast::TypeParams, TextSize), __3: (TextSize, ast::Arguments, TextSize), __4: (TextSize, token::Tok, TextSize), __5: (TextSize, ast::Suite, TextSize), @@ -71781,7 +71795,7 @@ fn __action1714< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, Vec, TextSize), + __3: (TextSize, ast::TypeParams, TextSize), __4: (TextSize, ast::Arguments, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Suite, TextSize), @@ -71846,7 +71860,7 @@ fn __action1716< mode: Mode, __0: (TextSize, token::Tok, TextSize), __1: (TextSize, ast::Identifier, TextSize), - __2: (TextSize, Vec, TextSize), + __2: (TextSize, ast::TypeParams, TextSize), __3: (TextSize, token::Tok, TextSize), __4: (TextSize, ast::Suite, TextSize), ) -> ast::Stmt @@ -71905,7 +71919,7 @@ fn __action1718< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, Vec, TextSize), + __3: (TextSize, ast::TypeParams, TextSize), __4: (TextSize, token::Tok, TextSize), __5: (TextSize, ast::Suite, TextSize), ) -> ast::Stmt @@ -71967,7 +71981,7 @@ fn __action1720< __0: (TextSize, token::Tok, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, Vec, TextSize), + __3: (TextSize, ast::TypeParams, TextSize), __4: (TextSize, ast::Parameters, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Expr, TextSize), @@ -72042,7 +72056,7 @@ fn __action1722< __1: (TextSize, token::Tok, TextSize), __2: (TextSize, token::Tok, TextSize), __3: (TextSize, ast::Identifier, TextSize), - __4: (TextSize, Vec, TextSize), + __4: (TextSize, ast::TypeParams, TextSize), __5: (TextSize, ast::Parameters, TextSize), __6: (TextSize, token::Tok, TextSize), __7: (TextSize, ast::Expr, TextSize), @@ -72119,7 +72133,7 @@ fn __action1724< __0: (TextSize, token::Tok, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, Vec, TextSize), + __3: (TextSize, ast::TypeParams, TextSize), __4: (TextSize, ast::Parameters, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Suite, TextSize), @@ -72186,7 +72200,7 @@ fn __action1726< __1: (TextSize, token::Tok, TextSize), __2: (TextSize, token::Tok, TextSize), __3: (TextSize, ast::Identifier, TextSize), - __4: (TextSize, Vec, TextSize), + __4: (TextSize, ast::TypeParams, TextSize), __5: (TextSize, ast::Parameters, TextSize), __6: (TextSize, token::Tok, TextSize), __7: (TextSize, ast::Suite, TextSize), @@ -72254,7 +72268,7 @@ fn __action1728< mode: Mode, __0: (TextSize, token::Tok, TextSize), __1: (TextSize, ast::Identifier, TextSize), - __2: (TextSize, Vec, TextSize), + __2: (TextSize, ast::TypeParams, TextSize), __3: (TextSize, ast::Parameters, TextSize), __4: (TextSize, token::Tok, TextSize), __5: (TextSize, ast::Expr, TextSize), @@ -72325,7 +72339,7 @@ fn __action1730< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, Vec, TextSize), + __3: (TextSize, ast::TypeParams, TextSize), __4: (TextSize, ast::Parameters, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Expr, TextSize), @@ -72398,7 +72412,7 @@ fn __action1732< mode: Mode, __0: (TextSize, token::Tok, TextSize), __1: (TextSize, ast::Identifier, TextSize), - __2: (TextSize, Vec, TextSize), + __2: (TextSize, ast::TypeParams, TextSize), __3: (TextSize, ast::Parameters, TextSize), __4: (TextSize, token::Tok, TextSize), __5: (TextSize, ast::Suite, TextSize), @@ -72461,7 +72475,7 @@ fn __action1734< __0: (TextSize, alloc::vec::Vec, TextSize), __1: (TextSize, token::Tok, TextSize), __2: (TextSize, ast::Identifier, TextSize), - __3: (TextSize, Vec, TextSize), + __3: (TextSize, ast::TypeParams, TextSize), __4: (TextSize, ast::Parameters, TextSize), __5: (TextSize, token::Tok, TextSize), __6: (TextSize, ast::Suite, TextSize), @@ -72526,7 +72540,7 @@ fn __action1736< mode: Mode, __0: (TextSize, token::Tok, TextSize), __1: (TextSize, ast::Expr, TextSize), - __2: (TextSize, Vec, TextSize), + __2: (TextSize, ast::TypeParams, TextSize), __3: (TextSize, token::Tok, TextSize), __4: (TextSize, ast::Expr, TextSize), ) -> ast::Stmt diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_kw_only_args.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_kw_only_args.snap index c35a7c4a0c..4e6cabe7e1 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_kw_only_args.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_kw_only_args.snap @@ -7,10 +7,12 @@ Ok( FunctionDef( StmtFunctionDef { range: 0..23, + decorator_list: [], name: Identifier { id: "f", range: 4..5, }, + type_params: None, parameters: Parameters { range: 5..17, posonlyargs: [], @@ -56,6 +58,7 @@ Ok( ], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -63,9 +66,6 @@ Ok( }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), ], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_kw_only_args_with_defaults.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_kw_only_args_with_defaults.snap index 410132392c..2008962778 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_kw_only_args_with_defaults.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_kw_only_args_with_defaults.snap @@ -7,10 +7,12 @@ Ok( FunctionDef( StmtFunctionDef { range: 0..29, + decorator_list: [], name: Identifier { id: "f", range: 4..5, }, + type_params: None, parameters: Parameters { range: 5..23, posonlyargs: [], @@ -76,6 +78,7 @@ Ok( ], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -83,9 +86,6 @@ Ok( }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), ], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_no_args.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_no_args.snap index 0e3d2d4e4b..2c5ceaf090 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_no_args.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_no_args.snap @@ -7,10 +7,12 @@ Ok( FunctionDef( StmtFunctionDef { range: 0..13, + decorator_list: [], name: Identifier { id: "f", range: 4..5, }, + type_params: None, parameters: Parameters { range: 5..7, posonlyargs: [], @@ -19,6 +21,7 @@ Ok( kwonlyargs: [], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -26,9 +29,6 @@ Ok( }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), ], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_no_args_with_ranges.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_no_args_with_ranges.snap index 0e3d2d4e4b..2c5ceaf090 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_no_args_with_ranges.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_no_args_with_ranges.snap @@ -7,10 +7,12 @@ Ok( FunctionDef( StmtFunctionDef { range: 0..13, + decorator_list: [], name: Identifier { id: "f", range: 4..5, }, + type_params: None, parameters: Parameters { range: 5..7, posonlyargs: [], @@ -19,6 +21,7 @@ Ok( kwonlyargs: [], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -26,9 +29,6 @@ Ok( }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), ], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args.snap index cf19d90622..5e32c2421e 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args.snap @@ -7,10 +7,12 @@ Ok( FunctionDef( StmtFunctionDef { range: 0..32, + decorator_list: [], name: Identifier { id: "f", range: 4..5, }, + type_params: None, parameters: Parameters { range: 5..26, posonlyargs: [], @@ -93,6 +95,7 @@ Ok( ], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -100,9 +103,6 @@ Ok( }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), ], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args_with_defaults.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args_with_defaults.snap index 4343d2588f..fe9ac3afcf 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args_with_defaults.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args_with_defaults.snap @@ -7,10 +7,12 @@ Ok( FunctionDef( StmtFunctionDef { range: 0..38, + decorator_list: [], name: Identifier { id: "f", range: 4..5, }, + type_params: None, parameters: Parameters { range: 5..32, posonlyargs: [], @@ -113,6 +115,7 @@ Ok( ], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -120,9 +123,6 @@ Ok( }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), ], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args_with_defaults_and_varargs.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args_with_defaults_and_varargs.snap index a980ddd42d..8944370563 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args_with_defaults_and_varargs.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args_with_defaults_and_varargs.snap @@ -7,10 +7,12 @@ Ok( FunctionDef( StmtFunctionDef { range: 0..42, + decorator_list: [], name: Identifier { id: "f", range: 4..5, }, + type_params: None, parameters: Parameters { range: 5..36, posonlyargs: [], @@ -122,6 +124,7 @@ Ok( ], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -129,9 +132,6 @@ Ok( }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), ], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args_with_defaults_and_varargs_and_kwargs.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args_with_defaults_and_varargs_and_kwargs.snap index 26c38e57f0..e5ef63795f 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args_with_defaults_and_varargs_and_kwargs.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_and_kw_only_args_with_defaults_and_varargs_and_kwargs.snap @@ -7,10 +7,12 @@ Ok( FunctionDef( StmtFunctionDef { range: 0..52, + decorator_list: [], name: Identifier { id: "f", range: 4..5, }, + type_params: None, parameters: Parameters { range: 5..46, posonlyargs: [], @@ -131,6 +133,7 @@ Ok( }, ), }, + returns: None, body: [ Pass( StmtPass { @@ -138,9 +141,6 @@ Ok( }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), ], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_args.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_args.snap index 294e0f6244..8a969a82e6 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_args.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_args.snap @@ -7,10 +7,12 @@ Ok( FunctionDef( StmtFunctionDef { range: 0..20, + decorator_list: [], name: Identifier { id: "f", range: 4..5, }, + type_params: None, parameters: Parameters { range: 5..14, posonlyargs: [], @@ -56,6 +58,7 @@ Ok( kwonlyargs: [], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -63,9 +66,6 @@ Ok( }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), ], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_args_with_defaults.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_args_with_defaults.snap index dd2d7e11d7..4f369f862b 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_args_with_defaults.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_args_with_defaults.snap @@ -7,10 +7,12 @@ Ok( FunctionDef( StmtFunctionDef { range: 0..26, + decorator_list: [], name: Identifier { id: "f", range: 4..5, }, + type_params: None, parameters: Parameters { range: 5..20, posonlyargs: [], @@ -76,6 +78,7 @@ Ok( kwonlyargs: [], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -83,9 +86,6 @@ Ok( }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), ], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_args_with_ranges.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_args_with_ranges.snap index 294e0f6244..8a969a82e6 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_args_with_ranges.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__function__tests__function_pos_args_with_ranges.snap @@ -7,10 +7,12 @@ Ok( FunctionDef( StmtFunctionDef { range: 0..20, + decorator_list: [], name: Identifier { id: "f", range: 4..5, }, + type_params: None, parameters: Parameters { range: 5..14, posonlyargs: [], @@ -56,6 +58,7 @@ Ok( kwonlyargs: [], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -63,9 +66,6 @@ Ok( }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), ], diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__decorator_ranges.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__decorator_ranges.snap index 18a4603dfe..b976725751 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__decorator_ranges.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__decorator_ranges.snap @@ -6,25 +6,6 @@ expression: parse_ast FunctionDef( StmtFunctionDef { range: 0..34, - name: Identifier { - id: "test", - range: 18..22, - }, - parameters: Parameters { - range: 22..24, - posonlyargs: [], - args: [], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - body: [ - Pass( - StmtPass { - range: 30..34, - }, - ), - ], decorator_list: [ Decorator { range: 0..13, @@ -37,26 +18,32 @@ expression: parse_ast ), }, ], + name: Identifier { + id: "test", + range: 18..22, + }, + type_params: None, + parameters: Parameters { + range: 22..24, + posonlyargs: [], + args: [], + vararg: None, + kwonlyargs: [], + kwarg: None, + }, returns: None, - type_params: [], + body: [ + Pass( + StmtPass { + range: 30..34, + }, + ), + ], }, ), ClassDef( StmtClassDef { range: 36..73, - name: Identifier { - id: "Abcd", - range: 59..63, - }, - arguments: None, - body: [ - Pass( - StmtPass { - range: 69..73, - }, - ), - ], - type_params: [], decorator_list: [ Decorator { range: 36..52, @@ -69,6 +56,19 @@ expression: parse_ast ), }, ], + name: Identifier { + id: "Abcd", + range: 59..63, + }, + type_params: None, + arguments: None, + body: [ + Pass( + StmtPass { + range: 69..73, + }, + ), + ], }, ), ] 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 27ce48d35d..adfa86aeed 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 @@ -125,10 +125,12 @@ Module( FunctionDef( StmtFunctionDef { range: 566..626, + decorator_list: [], name: Identifier { id: "foo", range: 570..573, }, + type_params: None, parameters: Parameters { range: 573..575, posonlyargs: [], @@ -137,6 +139,7 @@ Module( kwonlyargs: [], kwarg: None, }, + returns: None, body: [ Return( StmtReturn { @@ -170,9 +173,6 @@ Module( }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), LineMagic( diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class.snap index 22b263f422..9ac6469514 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class.snap @@ -6,10 +6,12 @@ expression: "parse_suite(source, \"\").unwrap()" ClassDef( StmtClassDef { range: 0..98, + decorator_list: [], name: Identifier { id: "Foo", range: 6..9, }, + type_params: None, arguments: Some( Arguments { range: 9..15, @@ -36,10 +38,12 @@ expression: "parse_suite(source, \"\").unwrap()" FunctionDef( StmtFunctionDef { range: 18..44, + decorator_list: [], name: Identifier { id: "__init__", range: 22..30, }, + type_params: None, parameters: Parameters { range: 30..36, posonlyargs: [], @@ -61,6 +65,7 @@ expression: "parse_suite(source, \"\").unwrap()" kwonlyargs: [], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -68,18 +73,17 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), FunctionDef( StmtFunctionDef { range: 46..98, + decorator_list: [], name: Identifier { id: "method_with_default", range: 50..69, }, + type_params: None, parameters: Parameters { range: 69..90, posonlyargs: [], @@ -123,6 +127,7 @@ expression: "parse_suite(source, \"\").unwrap()" kwonlyargs: [], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -130,14 +135,9 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), ], - type_params: [], - decorator_list: [], }, ), ] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class_generic_types.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class_generic_types.snap index 18f6fdfd06..7353f1cc14 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class_generic_types.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class_generic_types.snap @@ -6,10 +6,28 @@ expression: "parse_suite(source, \"\").unwrap()" ClassDef( StmtClassDef { range: 10..29, + decorator_list: [], name: Identifier { id: "Foo", range: 16..19, }, + type_params: Some( + TypeParams { + range: 19..22, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 20..21, + name: Identifier { + id: "T", + range: 20..21, + }, + bound: None, + }, + ), + ], + }, + ), arguments: Some( Arguments { range: 22..24, @@ -31,28 +49,41 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 20..21, - name: Identifier { - id: "T", - range: 20..21, - }, - bound: None, - }, - ), - ], - decorator_list: [], }, ), ClassDef( StmtClassDef { range: 52..76, + decorator_list: [], name: Identifier { id: "Foo", range: 58..61, }, + type_params: Some( + TypeParams { + range: 61..69, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 62..68, + name: Identifier { + id: "T", + range: 62..63, + }, + bound: Some( + Name( + ExprName { + range: 65..68, + id: "str", + ctx: Load, + }, + ), + ), + }, + ), + ], + }, + ), arguments: Some( Arguments { range: 69..71, @@ -74,36 +105,56 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 62..68, - name: Identifier { - id: "T", - range: 62..63, - }, - bound: Some( - Name( - ExprName { - range: 65..68, - id: "str", - ctx: Load, - }, - ), - ), - }, - ), - ], - decorator_list: [], }, ), ClassDef( StmtClassDef { range: 105..138, + decorator_list: [], name: Identifier { id: "Foo", range: 111..114, }, + type_params: Some( + TypeParams { + range: 114..131, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 115..130, + name: Identifier { + id: "T", + range: 115..116, + }, + bound: Some( + Tuple( + ExprTuple { + range: 118..130, + elts: [ + Name( + ExprName { + range: 119..122, + id: "str", + ctx: Load, + }, + ), + Name( + ExprName { + range: 124..129, + id: "bytes", + ctx: Load, + }, + ), + ], + ctx: Load, + }, + ), + ), + }, + ), + ], + }, + ), arguments: Some( Arguments { range: 131..133, @@ -125,51 +176,43 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 115..130, - name: Identifier { - id: "T", - range: 115..116, - }, - bound: Some( - Tuple( - ExprTuple { - range: 118..130, - elts: [ - Name( - ExprName { - range: 119..122, - id: "str", - ctx: Load, - }, - ), - Name( - ExprName { - range: 124..129, - id: "bytes", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - ), - }, - ), - ], - decorator_list: [], }, ), ClassDef( StmtClassDef { range: 159..181, + decorator_list: [], name: Identifier { id: "Foo", range: 165..168, }, + type_params: Some( + TypeParams { + range: 168..174, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 169..170, + name: Identifier { + id: "T", + range: 169..170, + }, + bound: None, + }, + ), + TypeVar( + TypeParamTypeVar { + range: 172..173, + name: Identifier { + id: "U", + range: 172..173, + }, + bound: None, + }, + ), + ], + }, + ), arguments: Some( Arguments { range: 174..176, @@ -191,38 +234,43 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 169..170, - name: Identifier { - id: "T", - range: 169..170, - }, - bound: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 172..173, - name: Identifier { - id: "U", - range: 172..173, - }, - bound: None, - }, - ), - ], - decorator_list: [], }, ), ClassDef( StmtClassDef { range: 200..223, + decorator_list: [], name: Identifier { id: "Foo", range: 206..209, }, + type_params: Some( + TypeParams { + range: 209..216, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 210..211, + name: Identifier { + id: "T", + range: 210..211, + }, + bound: None, + }, + ), + TypeVar( + TypeParamTypeVar { + range: 213..214, + name: Identifier { + id: "U", + range: 213..214, + }, + bound: None, + }, + ), + ], + }, + ), arguments: Some( Arguments { range: 216..218, @@ -244,38 +292,32 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 210..211, - name: Identifier { - id: "T", - range: 210..211, - }, - bound: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 213..214, - name: Identifier { - id: "U", - range: 213..214, - }, - bound: None, - }, - ), - ], - decorator_list: [], }, ), ClassDef( StmtClassDef { range: 240..261, + decorator_list: [], name: Identifier { id: "Foo", range: 246..249, }, + type_params: Some( + TypeParams { + range: 249..254, + type_params: [ + TypeVarTuple( + TypeParamTypeVarTuple { + range: 250..253, + name: Identifier { + id: "Ts", + range: 251..253, + }, + }, + ), + ], + }, + ), arguments: Some( Arguments { range: 254..256, @@ -297,27 +339,32 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 250..253, - name: Identifier { - id: "Ts", - range: 251..253, - }, - }, - ), - ], - decorator_list: [], }, ), ClassDef( StmtClassDef { range: 275..296, + decorator_list: [], name: Identifier { id: "Foo", range: 281..284, }, + type_params: Some( + TypeParams { + range: 284..289, + type_params: [ + ParamSpec( + TypeParamParamSpec { + range: 285..288, + name: Identifier { + id: "P", + range: 287..288, + }, + }, + ), + ], + }, + ), arguments: Some( Arguments { range: 289..291, @@ -339,27 +386,69 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 285..288, - name: Identifier { - id: "P", - range: 287..288, - }, - }, - ), - ], - decorator_list: [], }, ), ClassDef( StmtClassDef { range: 312..351, + decorator_list: [], name: Identifier { id: "Foo", range: 318..321, }, + type_params: Some( + TypeParams { + range: 321..341, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 322..323, + name: Identifier { + id: "X", + range: 322..323, + }, + bound: None, + }, + ), + TypeVar( + TypeParamTypeVar { + range: 325..331, + name: Identifier { + id: "Y", + range: 325..326, + }, + bound: Some( + Name( + ExprName { + range: 328..331, + id: "str", + ctx: Load, + }, + ), + ), + }, + ), + TypeVarTuple( + TypeParamTypeVarTuple { + range: 333..335, + name: Identifier { + id: "U", + range: 334..335, + }, + }, + ), + ParamSpec( + TypeParamParamSpec { + range: 337..340, + name: Identifier { + id: "P", + range: 339..340, + }, + }, + ), + ], + }, + ), arguments: Some( Arguments { range: 341..343, @@ -374,55 +463,6 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 322..323, - name: Identifier { - id: "X", - range: 322..323, - }, - bound: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 325..331, - name: Identifier { - id: "Y", - range: 325..326, - }, - bound: Some( - Name( - ExprName { - range: 328..331, - id: "str", - ctx: Load, - }, - ), - ), - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 333..335, - name: Identifier { - id: "U", - range: 334..335, - }, - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 337..340, - name: Identifier { - id: "P", - range: 339..340, - }, - }, - ), - ], - decorator_list: [], }, ), ] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_function_definition.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_function_definition.snap index 207228fe5c..1c03ac6610 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_function_definition.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_function_definition.snap @@ -6,10 +6,12 @@ expression: "parse_suite(source, \"\").unwrap()" FunctionDef( StmtFunctionDef { range: 0..20, + decorator_list: [], name: Identifier { id: "func", range: 4..8, }, + type_params: None, parameters: Parameters { range: 8..11, posonlyargs: [], @@ -31,6 +33,7 @@ expression: "parse_suite(source, \"\").unwrap()" kwonlyargs: [], kwarg: None, }, + returns: None, body: [ Expr( StmtExpr { @@ -45,18 +48,33 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - decorator_list: [], - returns: None, - type_params: [], }, ), FunctionDef( StmtFunctionDef { range: 22..53, + decorator_list: [], name: Identifier { id: "func", range: 26..30, }, + type_params: Some( + TypeParams { + range: 30..33, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 31..32, + name: Identifier { + id: "T", + range: 31..32, + }, + bound: None, + }, + ), + ], + }, + ), parameters: Parameters { range: 33..39, posonlyargs: [], @@ -86,6 +104,15 @@ expression: "parse_suite(source, \"\").unwrap()" kwonlyargs: [], kwarg: None, }, + returns: Some( + Name( + ExprName { + range: 43..44, + id: "T", + ctx: Load, + }, + ), + ), body: [ Expr( StmtExpr { @@ -100,37 +127,41 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - decorator_list: [], - returns: Some( - Name( - ExprName { - range: 43..44, - id: "T", - ctx: Load, - }, - ), - ), - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 31..32, - name: Identifier { - id: "T", - range: 31..32, - }, - bound: None, - }, - ), - ], }, ), FunctionDef( StmtFunctionDef { range: 55..91, + decorator_list: [], name: Identifier { id: "func", range: 59..63, }, + type_params: Some( + TypeParams { + range: 63..71, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 64..70, + name: Identifier { + id: "T", + range: 64..65, + }, + bound: Some( + Name( + ExprName { + range: 67..70, + id: "str", + ctx: Load, + }, + ), + ), + }, + ), + ], + }, + ), parameters: Parameters { range: 71..77, posonlyargs: [], @@ -160,6 +191,15 @@ expression: "parse_suite(source, \"\").unwrap()" kwonlyargs: [], kwarg: None, }, + returns: Some( + Name( + ExprName { + range: 81..82, + id: "T", + ctx: Load, + }, + ), + ), body: [ Expr( StmtExpr { @@ -174,45 +214,56 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - decorator_list: [], - returns: Some( - Name( - ExprName { - range: 81..82, - id: "T", - ctx: Load, - }, - ), - ), - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 64..70, - name: Identifier { - id: "T", - range: 64..65, - }, - bound: Some( - Name( - ExprName { - range: 67..70, - id: "str", - ctx: Load, - }, - ), - ), - }, - ), - ], }, ), FunctionDef( StmtFunctionDef { range: 93..138, + decorator_list: [], name: Identifier { id: "func", range: 97..101, }, + type_params: Some( + TypeParams { + range: 101..118, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 102..117, + name: Identifier { + id: "T", + range: 102..103, + }, + bound: Some( + Tuple( + ExprTuple { + range: 105..117, + elts: [ + Name( + ExprName { + range: 106..109, + id: "str", + ctx: Load, + }, + ), + Name( + ExprName { + range: 111..116, + id: "bytes", + ctx: Load, + }, + ), + ], + ctx: Load, + }, + ), + ), + }, + ), + ], + }, + ), parameters: Parameters { range: 118..124, posonlyargs: [], @@ -242,6 +293,15 @@ expression: "parse_suite(source, \"\").unwrap()" kwonlyargs: [], kwarg: None, }, + returns: Some( + Name( + ExprName { + range: 128..129, + id: "T", + ctx: Load, + }, + ), + ), body: [ Expr( StmtExpr { @@ -256,60 +316,32 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - decorator_list: [], - returns: Some( - Name( - ExprName { - range: 128..129, - id: "T", - ctx: Load, - }, - ), - ), - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 102..117, - name: Identifier { - id: "T", - range: 102..103, - }, - bound: Some( - Tuple( - ExprTuple { - range: 105..117, - elts: [ - Name( - ExprName { - range: 106..109, - id: "str", - ctx: Load, - }, - ), - Name( - ExprName { - range: 111..116, - id: "bytes", - ctx: Load, - }, - ), - ], - ctx: Load, - }, - ), - ), - }, - ), - ], }, ), FunctionDef( StmtFunctionDef { range: 140..171, + decorator_list: [], name: Identifier { id: "func", range: 144..148, }, + type_params: Some( + TypeParams { + range: 148..153, + type_params: [ + TypeVarTuple( + TypeParamTypeVarTuple { + range: 149..152, + name: Identifier { + id: "Ts", + range: 150..152, + }, + }, + ), + ], + }, + ), parameters: Parameters { range: 153..162, posonlyargs: [], @@ -341,6 +373,7 @@ expression: "parse_suite(source, \"\").unwrap()" kwonlyargs: [], kwarg: None, }, + returns: None, body: [ Expr( StmtExpr { @@ -355,28 +388,32 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - decorator_list: [], - returns: None, - type_params: [ - TypeVarTuple( - TypeParamTypeVarTuple { - range: 149..152, - name: Identifier { - id: "Ts", - range: 150..152, - }, - }, - ), - ], }, ), FunctionDef( StmtFunctionDef { range: 173..230, + decorator_list: [], name: Identifier { id: "func", range: 177..181, }, + type_params: Some( + TypeParams { + range: 181..186, + type_params: [ + ParamSpec( + TypeParamParamSpec { + range: 182..185, + name: Identifier { + id: "P", + range: 184..185, + }, + }, + ), + ], + }, + ), parameters: Parameters { range: 186..221, posonlyargs: [], @@ -439,6 +476,7 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), }, + returns: None, body: [ Expr( StmtExpr { @@ -453,28 +491,69 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - decorator_list: [], - returns: None, - type_params: [ - ParamSpec( - TypeParamParamSpec { - range: 182..185, - name: Identifier { - id: "P", - range: 184..185, - }, - }, - ), - ], }, ), FunctionDef( StmtFunctionDef { range: 232..273, + decorator_list: [], name: Identifier { id: "func", range: 236..240, }, + type_params: Some( + TypeParams { + range: 240..261, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 241..242, + name: Identifier { + id: "T", + range: 241..242, + }, + bound: None, + }, + ), + TypeVar( + TypeParamTypeVar { + range: 244..250, + name: Identifier { + id: "U", + range: 244..245, + }, + bound: Some( + Name( + ExprName { + range: 247..250, + id: "str", + ctx: Load, + }, + ), + ), + }, + ), + TypeVarTuple( + TypeParamTypeVarTuple { + range: 252..255, + name: Identifier { + id: "Ts", + range: 253..255, + }, + }, + ), + ParamSpec( + TypeParamParamSpec { + range: 257..260, + name: Identifier { + id: "P", + range: 259..260, + }, + }, + ), + ], + }, + ), parameters: Parameters { range: 261..263, posonlyargs: [], @@ -483,6 +562,7 @@ expression: "parse_suite(source, \"\").unwrap()" kwonlyargs: [], kwarg: None, }, + returns: None, body: [ Pass( StmtPass { @@ -490,56 +570,6 @@ expression: "parse_suite(source, \"\").unwrap()" }, ), ], - decorator_list: [], - returns: None, - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 241..242, - name: Identifier { - id: "T", - range: 241..242, - }, - bound: None, - }, - ), - TypeVar( - TypeParamTypeVar { - range: 244..250, - name: Identifier { - id: "U", - range: 244..245, - }, - bound: Some( - Name( - ExprName { - range: 247..250, - id: "str", - ctx: Load, - }, - ), - ), - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 252..255, - name: Identifier { - id: "Ts", - range: 253..255, - }, - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 257..260, - name: Identifier { - id: "P", - range: 259..260, - }, - }, - ), - ], }, ), ] diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_type_declaration.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_type_declaration.snap index a0bc32044f..d2763aee2e 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_type_declaration.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_type_declaration.snap @@ -1,6 +1,6 @@ --- source: crates/ruff_python_parser/src/parser.rs -expression: "ast::Suite::parse(source, \"\").unwrap()" +expression: "parse_suite(source, \"\").unwrap()" --- [ TypeAlias( @@ -13,7 +13,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: Name( ExprName { range: 10..13, @@ -33,7 +33,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: BinOp( ExprBinOp { range: 23..32, @@ -66,7 +66,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: BinOp( ExprBinOp { range: 42..61, @@ -101,18 +101,23 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 69..70, - name: Identifier { - id: "T", - range: 69..70, - }, - bound: None, - }, - ), - ], + type_params: Some( + TypeParams { + range: 68..71, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 69..70, + name: Identifier { + id: "T", + range: 69..70, + }, + bound: None, + }, + ), + ], + }, + ), value: BinOp( ExprBinOp { range: 74..88, @@ -171,18 +176,23 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 109..110, - name: Identifier { - id: "T", - range: 109..110, - }, - bound: None, - }, - ), - ], + type_params: Some( + TypeParams { + range: 108..111, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 109..110, + name: Identifier { + id: "T", + range: 109..110, + }, + bound: None, + }, + ), + ], + }, + ), value: Name( ExprName { range: 114..117, @@ -202,18 +212,23 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 125..126, - name: Identifier { - id: "T", - range: 125..126, - }, - bound: None, - }, - ), - ], + type_params: Some( + TypeParams { + range: 124..127, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 125..126, + name: Identifier { + id: "T", + range: 125..126, + }, + bound: None, + }, + ), + ], + }, + ), value: BinOp( ExprBinOp { range: 130..146, @@ -272,36 +287,41 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 154..155, - name: Identifier { - id: "T", - range: 154..155, - }, - bound: None, - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 157..160, - name: Identifier { - id: "Ts", - range: 158..160, - }, - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 162..165, - name: Identifier { - id: "P", - range: 164..165, - }, - }, - ), - ], + type_params: Some( + TypeParams { + range: 153..166, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 154..155, + name: Identifier { + id: "T", + range: 154..155, + }, + bound: None, + }, + ), + TypeVarTuple( + TypeParamTypeVarTuple { + range: 157..160, + name: Identifier { + id: "Ts", + range: 158..160, + }, + }, + ), + ParamSpec( + TypeParamParamSpec { + range: 162..165, + name: Identifier { + id: "P", + range: 164..165, + }, + }, + ), + ], + }, + ), value: Tuple( ExprTuple { range: 169..179, @@ -343,44 +363,49 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 187..193, - name: Identifier { - id: "T", - range: 187..188, - }, - bound: Some( - Name( - ExprName { - range: 190..193, - id: "int", - ctx: Load, + type_params: Some( + TypeParams { + range: 186..204, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 187..193, + name: Identifier { + id: "T", + range: 187..188, }, - ), + bound: Some( + Name( + ExprName { + range: 190..193, + id: "int", + ctx: Load, + }, + ), + ), + }, ), - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 195..198, - name: Identifier { - id: "Ts", - range: 196..198, - }, - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 200..203, - name: Identifier { - id: "P", - range: 202..203, - }, - }, - ), - ], + TypeVarTuple( + TypeParamTypeVarTuple { + range: 195..198, + name: Identifier { + id: "Ts", + range: 196..198, + }, + }, + ), + ParamSpec( + TypeParamParamSpec { + range: 200..203, + name: Identifier { + id: "P", + range: 202..203, + }, + }, + ), + ], + }, + ), value: Tuple( ExprTuple { range: 207..217, @@ -422,59 +447,64 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 225..238, - name: Identifier { - id: "T", - range: 225..226, - }, - bound: Some( - Tuple( - ExprTuple { - range: 228..238, - elts: [ - Name( - ExprName { - range: 229..232, - id: "int", - ctx: Load, - }, - ), - Name( - ExprName { - range: 234..237, - id: "str", - ctx: Load, - }, - ), - ], - ctx: Load, + type_params: Some( + TypeParams { + range: 224..249, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 225..238, + name: Identifier { + id: "T", + range: 225..226, }, - ), + bound: Some( + Tuple( + ExprTuple { + range: 228..238, + elts: [ + Name( + ExprName { + range: 229..232, + id: "int", + ctx: Load, + }, + ), + Name( + ExprName { + range: 234..237, + id: "str", + ctx: Load, + }, + ), + ], + ctx: Load, + }, + ), + ), + }, ), - }, - ), - TypeVarTuple( - TypeParamTypeVarTuple { - range: 240..243, - name: Identifier { - id: "Ts", - range: 241..243, - }, - }, - ), - ParamSpec( - TypeParamParamSpec { - range: 245..248, - name: Identifier { - id: "P", - range: 247..248, - }, - }, - ), - ], + TypeVarTuple( + TypeParamTypeVarTuple { + range: 240..243, + name: Identifier { + id: "Ts", + range: 241..243, + }, + }, + ), + ParamSpec( + TypeParamParamSpec { + range: 245..248, + name: Identifier { + id: "P", + range: 247..248, + }, + }, + ), + ], + }, + ), value: Tuple( ExprTuple { range: 252..262, @@ -516,7 +546,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: Name( ExprName { range: 305..308, @@ -536,7 +566,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: Name( ExprName { range: 322..325, @@ -556,7 +586,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: Name( ExprName { range: 338..341, @@ -576,7 +606,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: Name( ExprName { range: 378..382, @@ -596,7 +626,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: Name( ExprName { range: 394..399, @@ -616,7 +646,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: Name( ExprName { range: 411..415, @@ -636,7 +666,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: Name( ExprName { range: 451..454, @@ -656,7 +686,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: Name( ExprName { range: 467..470, @@ -676,7 +706,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: Name( ExprName { range: 483..486, @@ -696,7 +726,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [], + type_params: None, value: Name( ExprName { range: 502..505, @@ -716,18 +746,23 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 521..522, - name: Identifier { - id: "T", - range: 521..522, - }, - bound: None, - }, - ), - ], + type_params: Some( + TypeParams { + range: 520..523, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 521..522, + name: Identifier { + id: "T", + range: 521..522, + }, + bound: None, + }, + ), + ], + }, + ), value: Name( ExprName { range: 526..527, @@ -747,18 +782,23 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 542..543, - name: Identifier { - id: "T", - range: 542..543, - }, - bound: None, - }, - ), - ], + type_params: Some( + TypeParams { + range: 541..544, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 542..543, + name: Identifier { + id: "T", + range: 542..543, + }, + bound: None, + }, + ), + ], + }, + ), value: Name( ExprName { range: 547..548, @@ -778,18 +818,23 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" ctx: Store, }, ), - type_params: [ - TypeVar( - TypeParamTypeVar { - range: 556..557, - name: Identifier { - id: "T", - range: 556..557, - }, - bound: None, - }, - ), - ], + type_params: Some( + TypeParams { + range: 555..558, + type_params: [ + TypeVar( + TypeParamTypeVar { + range: 556..557, + name: Identifier { + id: "T", + range: 556..557, + }, + bound: None, + }, + ), + ], + }, + ), value: Name( ExprName { range: 567..568, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__variadic_generics.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__variadic_generics.snap index 0487206d18..ec38d5c16b 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__variadic_generics.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__variadic_generics.snap @@ -6,10 +6,12 @@ expression: parse_ast FunctionDef( StmtFunctionDef { range: 1..49, + decorator_list: [], name: Identifier { id: "args_to_tuple", range: 5..18, }, + type_params: None, parameters: Parameters { range: 18..30, posonlyargs: [], @@ -41,21 +43,6 @@ expression: parse_ast kwonlyargs: [], kwarg: None, }, - body: [ - Expr( - StmtExpr { - range: 46..49, - value: Constant( - ExprConstant { - range: 46..49, - value: Ellipsis, - kind: None, - }, - ), - }, - ), - ], - decorator_list: [], returns: Some( Subscript( ExprSubscript { @@ -84,7 +71,20 @@ expression: parse_ast }, ), ), - type_params: [], + body: [ + Expr( + StmtExpr { + range: 46..49, + value: Constant( + ExprConstant { + range: 46..49, + value: Ellipsis, + kind: None, + }, + ), + }, + ), + ], }, ), ]