Commit b2b06576 authored by Kevin Modzelewski's avatar Kevin Modzelewski

test the order of decorators and defaults evaluation

parent fe918ed5
...@@ -859,6 +859,7 @@ public: ...@@ -859,6 +859,7 @@ public:
remapped->args = new AST_arguments(); remapped->args = new AST_arguments();
remapped->body = node->body; // hmm shouldnt have to copy this remapped->body = node->body; // hmm shouldnt have to copy this
// Decorators are evaluated before the defaults:
for (auto d : node->decorator_list) { for (auto d : node->decorator_list) {
remapped->decorator_list.push_back(remapExpr(d)); remapped->decorator_list.push_back(remapExpr(d));
} }
......
# expected: fail
# - decorators
def print_when_eval(x, msg):
print msg
return x
# Test the order that decorators and function defaults get evaluated
@print_when_eval(lambda f: print_when_eval(f, "calling decorator"), "evaluating decorator")
def f(x=print_when_eval(1, "evaluating default")):
pass
# Result: looks like it's decorator first, then defaults, then the decorator is called.
...@@ -43,6 +43,11 @@ def wrapper(): ...@@ -43,6 +43,11 @@ def wrapper():
print X, Y # "1 1" print X, Y # "1 1"
print "done with classdef" print "done with classdef"
print hasattr(C, 'X')
print hasattr(C, 'Y')
print hasattr(C, 'Z')
print hasattr(C, 'W')
return C return C
wrapper()().f() wrapper()().f()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment