@@ -23,7 +23,9 @@ pub enum Ast<R = TextRange> {
23
23
Pattern ( Pattern < R > ) ,
24
24
TypeIgnore ( TypeIgnore < R > ) ,
25
25
TypeParam ( TypeParam < R > ) ,
26
+ Decorator ( Decorator < R > ) ,
26
27
}
28
+
27
29
impl < R > Node for Ast < R > {
28
30
const NAME : & ' static str = "AST" ;
29
31
const FIELD_NAMES : & ' static [ & ' static str ] = & [ ] ;
@@ -143,6 +145,12 @@ impl<R> From<TypeParam<R>> for Ast<R> {
143
145
}
144
146
}
145
147
148
+ impl < R > From < Decorator < R > > for Ast < R > {
149
+ fn from ( node : Decorator < R > ) -> Self {
150
+ Ast :: Decorator ( node)
151
+ }
152
+ }
153
+
146
154
/// See also [mod](https://docs.python.org/3/library/ast.html#ast.mod)
147
155
#[ derive( Clone , Debug , PartialEq , is_macro:: Is ) ]
148
156
pub enum Mod < R = TextRange > {
@@ -315,7 +323,7 @@ pub struct StmtFunctionDef<R = TextRange> {
315
323
pub name : Identifier ,
316
324
pub args : Box < Arguments < R > > ,
317
325
pub body : Vec < Stmt < R > > ,
318
- pub decorator_list : Vec < Expr < R > > ,
326
+ pub decorator_list : Vec < Decorator < R > > ,
319
327
pub returns : Option < Box < Expr < R > > > ,
320
328
pub type_comment : Option < String > ,
321
329
pub type_params : Vec < TypeParam < R > > ,
@@ -351,7 +359,7 @@ pub struct StmtAsyncFunctionDef<R = TextRange> {
351
359
pub name : Identifier ,
352
360
pub args : Box < Arguments < R > > ,
353
361
pub body : Vec < Stmt < R > > ,
354
- pub decorator_list : Vec < Expr < R > > ,
362
+ pub decorator_list : Vec < Decorator < R > > ,
355
363
pub returns : Option < Box < Expr < R > > > ,
356
364
pub type_comment : Option < String > ,
357
365
pub type_params : Vec < TypeParam < R > > ,
@@ -388,7 +396,7 @@ pub struct StmtClassDef<R = TextRange> {
388
396
pub bases : Vec < Expr < R > > ,
389
397
pub keywords : Vec < Keyword < R > > ,
390
398
pub body : Vec < Stmt < R > > ,
391
- pub decorator_list : Vec < Expr < R > > ,
399
+ pub decorator_list : Vec < Decorator < R > > ,
392
400
pub type_params : Vec < TypeParam < R > > ,
393
401
}
394
402
@@ -3197,6 +3205,18 @@ impl<R> Node for TypeParam<R> {
3197
3205
const FIELD_NAMES : & ' static [ & ' static str ] = & [ ] ;
3198
3206
}
3199
3207
3208
+ /// See also [decorator](https://docs.python.org/3/library/ast.html#ast.decorator)
3209
+ #[ derive( Clone , Debug , PartialEq ) ]
3210
+ pub struct Decorator < R = TextRange > {
3211
+ pub range : OptionalRange < R > ,
3212
+ pub expression : Expr < R > ,
3213
+ }
3214
+
3215
+ impl < R > Node for Decorator < R > {
3216
+ const NAME : & ' static str = "decorator" ;
3217
+ const FIELD_NAMES : & ' static [ & ' static str ] = & [ "expression" ] ;
3218
+ }
3219
+
3200
3220
/// An alternative type of AST `arguments`. This is parser-friendly and human-friendly definition of function arguments.
3201
3221
/// This form also has advantage to implement pre-order traverse.
3202
3222
/// `defaults` and `kw_defaults` fields are removed and the default values are placed under each `arg_with_default` typed argument.
0 commit comments