Skip to content

Commit 42bb346

Browse files
Merge pull request RustPython#790 from skinny121/decorator_and_defaults
Fix decorator on functions with defaults
2 parents b90a1cf + 7fffc57 commit 42bb346

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

tests/snippets/decorators.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ def add(a, b):
1515
assert c == 14
1616

1717

18+
@logged
19+
def add3(a, b, c=2):
20+
return a + b + c
21+
22+
23+
d = add3(12, 5)
24+
25+
assert d == 20
26+
27+
1828
def f(func): return lambda: 42
1929
class A: pass
2030
a = A()

vm/src/compile.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@ impl Compiler {
585585
let was_in_function_def = self.in_function_def;
586586
self.in_loop = false;
587587
self.in_function_def = true;
588+
589+
self.prepare_decorators(decorator_list)?;
590+
588591
let mut flags = self.enter_function(name, args)?;
589592

590593
let (new_body, doc_str) = get_doc(body);
@@ -598,8 +601,6 @@ impl Compiler {
598601
self.emit(Instruction::ReturnValue);
599602
let code = self.pop_code_object();
600603

601-
self.prepare_decorators(decorator_list)?;
602-
603604
// Prepare type annotations:
604605
let mut num_annotations = 0;
605606

0 commit comments

Comments
 (0)