@@ -23,6 +23,7 @@ pub enum Ast<R = TextRange> {
23
23
MatchCase ( MatchCase < R > ) ,
24
24
Pattern ( Pattern < R > ) ,
25
25
TypeIgnore ( TypeIgnore < R > ) ,
26
+ Decorator ( Decorator < R > ) ,
26
27
}
27
28
impl < R > Node for Ast < R > {
28
29
const NAME : & ' static str = "AST" ;
@@ -137,6 +138,12 @@ impl<R> From<TypeIgnore<R>> for Ast<R> {
137
138
}
138
139
}
139
140
141
+ impl < R > From < Decorator < R > > for Ast < R > {
142
+ fn from ( node : Decorator < R > ) -> Self {
143
+ Ast :: Decorator ( node)
144
+ }
145
+ }
146
+
140
147
/// See also [mod](https://docs.python.org/3/library/ast.html#ast.mod)
141
148
#[ derive( Clone , Debug , PartialEq , is_macro:: Is ) ]
142
149
pub enum Mod < R = TextRange > {
@@ -307,7 +314,7 @@ pub struct StmtFunctionDef<R = TextRange> {
307
314
pub name : Identifier ,
308
315
pub args : Box < Arguments < R > > ,
309
316
pub body : Vec < Stmt < R > > ,
310
- pub decorator_list : Vec < Expr < R > > ,
317
+ pub decorator_list : Vec < Decorator < R > > ,
311
318
pub returns : Option < Box < Expr < R > > > ,
312
319
pub type_comment : Option < String > ,
313
320
}
@@ -341,7 +348,7 @@ pub struct StmtAsyncFunctionDef<R = TextRange> {
341
348
pub name : Identifier ,
342
349
pub args : Box < Arguments < R > > ,
343
350
pub body : Vec < Stmt < R > > ,
344
- pub decorator_list : Vec < Expr < R > > ,
351
+ pub decorator_list : Vec < Decorator < R > > ,
345
352
pub returns : Option < Box < Expr < R > > > ,
346
353
pub type_comment : Option < String > ,
347
354
}
@@ -376,7 +383,7 @@ pub struct StmtClassDef<R = TextRange> {
376
383
pub bases : Vec < Expr < R > > ,
377
384
pub keywords : Vec < Keyword < R > > ,
378
385
pub body : Vec < Stmt < R > > ,
379
- pub decorator_list : Vec < Expr < R > > ,
386
+ pub decorator_list : Vec < Decorator < R > > ,
380
387
}
381
388
382
389
impl < R > Node for StmtClassDef < R > {
@@ -3074,6 +3081,18 @@ impl<R> Node for TypeIgnore<R> {
3074
3081
const FIELD_NAMES : & ' static [ & ' static str ] = & [ ] ;
3075
3082
}
3076
3083
3084
+ /// See also [decorator](https://docs.python.org/3/library/ast.html#ast.decorator)
3085
+ #[ derive( Clone , Debug , PartialEq ) ]
3086
+ pub struct Decorator < R = TextRange > {
3087
+ pub range : OptionalRange < R > ,
3088
+ pub expression : Expr < R > ,
3089
+ }
3090
+
3091
+ impl < R > Node for Decorator < R > {
3092
+ const NAME : & ' static str = "decorator" ;
3093
+ const FIELD_NAMES : & ' static [ & ' static str ] = & [ "expression" ] ;
3094
+ }
3095
+
3077
3096
/// An alternative type of AST `arguments`. This is parser-friendly and human-friendly definition of function arguments.
3078
3097
/// This form also has advantage to implement pre-order traverse.
3079
3098
/// `defaults` and `kw_defaults` fields are removed and the default values are placed under each `arg_with_default` typed argument.
0 commit comments