mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 07:38:00 +00:00
Add a TypeParams
node to the AST (#6261)
## Summary Similar to #6259, this PR adds a `TypeParams` node to the AST, to capture the list of type parameters with their surrounding brackets. If a statement lacks type parameters, the `type_params` field will be `None`.
This commit is contained in:
parent
981e64f82b
commit
b095b7204b
31 changed files with 1104 additions and 866 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue