Skip to content

Commit

Permalink
Merge pull request #2 from astral-sh/include-decorators-in-class-and-…
Browse files Browse the repository at this point in the history
…func-range
  • Loading branch information
MichaReiser authored May 22, 2023
2 parents e1f02fc + 41a0ef8 commit 335780a
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 25 deletions.
20 changes: 20 additions & 0 deletions parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,4 +853,24 @@ def args_to_tuple(*args: *Ts) -> Tuple[*Ts]: ...
.unwrap();
insta::assert_debug_snapshot!(parse_ast);
}

#[test]
#[cfg(not(feature = "all-nodes-with-ranges"))]
fn decorator_ranges() {
let parse_ast = parse_program(
r#"
@my_decorator
def test():
pass
@class_decorator
class Abcd:
pass
"#
.trim(),
"<test>",
)
.unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
}
4 changes: 2 additions & 2 deletions parser/src/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ WithItem<Goal>: ast::Withitem = {
};

FuncDef: ast::Stmt = {
<decorator_list:Decorator*> <location:@L> <is_async:"async"?> "def" <name:Identifier> <args:Parameters> <r:("->" <Test<"all">>)?> ":" <body:Suite> => {
<location:@L> <decorator_list:Decorator*> <is_async:"async"?> "def" <name:Identifier> <args:Parameters> <r:("->" <Test<"all">>)?> ":" <body:Suite> => {
let args = Box::new(args);
let returns = r.map(|x| Box::new(x));
let end_location = body.last().unwrap().end();
Expand Down Expand Up @@ -1135,7 +1135,7 @@ KwargParameter<ArgType>: Option<Box<ast::Arg>> = {
};

ClassDef: ast::Stmt = {
<decorator_list:Decorator*> <location:@L> "class" <name:Identifier> <a:("(" ArgumentList ")")?> ":" <body:Suite> => {
<location:@L> <decorator_list:Decorator*> "class" <name:Identifier> <a:("(" ArgumentList ")")?> ":" <body:Suite> => {
let (bases, keywords) = match a {
Some((_, arg, _)) => (arg.args, arg.keywords),
None => (vec![], vec![]),
Expand Down
46 changes: 23 additions & 23 deletions parser/src/python.rs

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

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

0 comments on commit 335780a

Please sign in to comment.