Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Include decorators in Class and FunctionDef range #2

Merged
merged 2 commits into from
May 22, 2023
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
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.