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

Commit 335780a

Browse files
authored
Merge pull request #2 from astral-sh/include-decorators-in-class-and-func-range
2 parents e1f02fc + 41a0ef8 commit 335780a

File tree

4 files changed

+117
-25
lines changed

4 files changed

+117
-25
lines changed

parser/src/parser.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,4 +853,24 @@ def args_to_tuple(*args: *Ts) -> Tuple[*Ts]: ...
853853
.unwrap();
854854
insta::assert_debug_snapshot!(parse_ast);
855855
}
856+
857+
#[test]
858+
#[cfg(not(feature = "all-nodes-with-ranges"))]
859+
fn decorator_ranges() {
860+
let parse_ast = parse_program(
861+
r#"
862+
@my_decorator
863+
def test():
864+
pass
865+
866+
@class_decorator
867+
class Abcd:
868+
pass
869+
"#
870+
.trim(),
871+
"<test>",
872+
)
873+
.unwrap();
874+
insta::assert_debug_snapshot!(parse_ast);
875+
}
856876
}

parser/src/python.lalrpop

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ WithItem<Goal>: ast::Withitem = {
964964
};
965965

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

11371137
ClassDef: ast::Stmt = {
1138-
<decorator_list:Decorator*> <location:@L> "class" <name:Identifier> <a:("(" ArgumentList ")")?> ":" <body:Suite> => {
1138+
<location:@L> <decorator_list:Decorator*> "class" <name:Identifier> <a:("(" ArgumentList ")")?> ":" <body:Suite> => {
11391139
let (bases, keywords) = match a {
11401140
Some((_, arg, _)) => (arg.args, arg.keywords),
11411141
None => (vec![], vec![]),

parser/src/python.rs

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__parser__tests__decorator_ranges.snap

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)