Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions crates/ruff_python_ast/ast.toml
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,27 @@ fields = [{ name = "patterns", type = "Pattern*" }]
[TypeParam]
doc = "See also [type_param](https://docs.python.org/3/library/ast.html#ast.type_param)"

[TypeParam.nodes]
TypeParamTypeVar = {}
TypeParamTypeVarTuple = {}
TypeParamParamSpec = {}
[TypeParam.nodes.TypeParamTypeVar]
doc = "See also [TypeVar](https://docs.python.org/3/library/ast.html#ast.TypeVar)"
fields = [
{ name = "name", type = "Identifier" },
{ name = "bound", type = "Box<Expr>?" },
{ name = "default", type = "Box<Expr>?" },
]

[TypeParam.nodes.TypeParamTypeVarTuple]
doc = "See also [TypeVarTuple](https://docs.python.org/3/library/ast.html#ast.TypeVarTuple)"
fields = [
{ name = "name", type = "Identifier" },
{ name = "default", type = "Box<Expr>?" },
]

[TypeParam.nodes.TypeParamParamSpec]
doc = "See also [ParamSpec](https://docs.python.org/3/library/ast.html#ast.ParamSpec)"
fields = [
{ name = "name", type = "Identifier" },
{ name = "default", type = "Box<Expr>?" },
]

[ungrouped.nodes]
InterpolatedStringFormatSpec = {}
Expand Down
93 changes: 93 additions & 0 deletions crates/ruff_python_ast/src/generated.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 0 additions & 61 deletions crates/ruff_python_ast/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,67 +506,6 @@ impl ast::TypeParams {
}
}

impl ast::TypeParamTypeVar {
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
V: SourceOrderVisitor<'a> + ?Sized,
{
let ast::TypeParamTypeVar {
bound,
default,
name,
range: _,
node_index: _,
} = self;

visitor.visit_identifier(name);
if let Some(expr) = bound {
visitor.visit_expr(expr);
}
if let Some(expr) = default {
visitor.visit_expr(expr);
}
}
}

impl ast::TypeParamTypeVarTuple {
#[inline]
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
V: SourceOrderVisitor<'a> + ?Sized,
{
let ast::TypeParamTypeVarTuple {
range: _,
node_index: _,
name,
default,
} = self;
visitor.visit_identifier(name);
if let Some(expr) = default {
visitor.visit_expr(expr);
}
}
}

impl ast::TypeParamParamSpec {
#[inline]
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
V: SourceOrderVisitor<'a> + ?Sized,
{
let ast::TypeParamParamSpec {
range: _,
node_index: _,
name,
default,
} = self;
visitor.visit_identifier(name);
if let Some(expr) = default {
visitor.visit_expr(expr);
}
}
}

impl ast::FString {
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
Expand Down
31 changes: 0 additions & 31 deletions crates/ruff_python_ast/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2892,37 +2892,6 @@ impl TypeParam {
}
}

/// See also [TypeVar](https://docs.python.org/3/library/ast.html#ast.TypeVar)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct TypeParamTypeVar {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
pub name: Identifier,
pub bound: Option<Box<Expr>>,
pub default: Option<Box<Expr>>,
}

/// See also [ParamSpec](https://docs.python.org/3/library/ast.html#ast.ParamSpec)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct TypeParamParamSpec {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
pub name: Identifier,
pub default: Option<Box<Expr>>,
}

/// See also [TypeVarTuple](https://docs.python.org/3/library/ast.html#ast.TypeVarTuple)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct TypeParamTypeVarTuple {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
pub name: Identifier,
pub default: Option<Box<Expr>>,
}

/// See also [decorator](https://docs.python.org/3/library/ast.html#ast.decorator)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Module(
type_params: [
TypeVar(
TypeParamTypeVar {
range: 10..12,
node_index: NodeIndex(None),
range: 10..12,
name: Identifier {
id: Name("T1"),
range: 10..12,
Expand All @@ -40,8 +40,8 @@ Module(
),
TypeVarTuple(
TypeParamTypeVarTuple {
range: 14..17,
node_index: NodeIndex(None),
range: 14..17,
name: Identifier {
id: Name("T2"),
range: 15..17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Module(
type_params: [
TypeVar(
TypeParamTypeVar {
range: 54..69,
node_index: NodeIndex(None),
range: 54..69,
name: Identifier {
id: Name("S"),
range: 54..55,
Expand Down Expand Up @@ -67,8 +67,8 @@ Module(
),
TypeVar(
TypeParamTypeVar {
range: 71..79,
node_index: NodeIndex(None),
range: 71..79,
name: Identifier {
id: Name("T"),
range: 71..72,
Expand All @@ -89,8 +89,8 @@ Module(
),
TypeVarTuple(
TypeParamTypeVarTuple {
range: 81..84,
node_index: NodeIndex(None),
range: 81..84,
name: Identifier {
id: Name("Ts"),
range: 82..84,
Expand All @@ -101,8 +101,8 @@ Module(
),
ParamSpec(
TypeParamParamSpec {
range: 86..89,
node_index: NodeIndex(None),
range: 86..89,
name: Identifier {
id: Name("P"),
range: 88..89,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ Module(
type_params: [
TypeVar(
TypeParamTypeVar {
range: 43..52,
node_index: NodeIndex(None),
range: 43..52,
name: Identifier {
id: Name("__debug__"),
range: 43..52,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ Module(
type_params: [
TypeVar(
TypeParamTypeVar {
range: 44..53,
node_index: NodeIndex(None),
range: 44..53,
name: Identifier {
id: Name("__debug__"),
range: 44..53,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Module(
type_params: [
TypeVar(
TypeParamTypeVar {
range: 78..87,
node_index: NodeIndex(None),
range: 78..87,
name: Identifier {
id: Name("__debug__"),
range: 78..87,
Expand Down
Loading