Skip to content

Commit 406d92c

Browse files
committed
register decorators as possible cells
1 parent 8817cd8 commit 406d92c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,13 @@ def test_lambda_no_args_with_nested_lambdas():
8888

8989
def test_byte_numeric_escapes():
9090
assert eval('b"PK\\005\\006\\00\\11\\22\\08"') == b'PK\x05\x06\x00\t\x12\x008'
91+
92+
93+
def test_decorator_cell():
94+
foo = lambda x: "just a string, not %s" % x.__name__
95+
def run_me():
96+
@foo
97+
def func():
98+
pass
99+
return func
100+
assert run_me() == "just a string, not func", run_me()

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/ScopeTranslator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,14 @@ public T visitEval_input(Python3Parser.Eval_inputContext ctx) {
100100
}
101101
}
102102

103+
@Override
104+
public T visitDecorator(Python3Parser.DecoratorContext ctx) {
105+
registerPossibleCell(ctx.dotted_name().NAME(0).getText());
106+
return super.visitDecorator(ctx);
107+
}
108+
103109
@Override
104110
public T visitFuncdef(Python3Parser.FuncdefContext ctx) {
105-
if (ctx.parent instanceof Python3Parser.DecoratedContext) {
106-
// TODO: get the decorators
107-
}
108111
environment.createLocal(ctx.NAME().getText());
109112
ArgListCompiler<T> argListCompiler = new ArgListCompiler<>(errors);
110113
argListCompilers.add(argListCompiler);

0 commit comments

Comments
 (0)