Skip to content

Commit 5ec34d7

Browse files
committed
Evaluate parameter annotations in outer scope
1 parent e3b64a6 commit 5ec34d7

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,9 @@ def test_underscore_in_numbers():
121121
assert eval('0b1_1') == 0b11
122122
assert eval('0o1_7') == 0o17
123123
assert eval('0x1_f') == 0x1f
124+
125+
126+
def test_annotation_scope():
127+
def foo(object: object):
128+
pass
129+
assert foo.__annotations__['object'] == object

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/sst/FactorySSTVisitor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,12 @@ public PNode visit(FunctionDefSSTNode node) {
783783
returnTarget = new ReturnTargetNode(body, nodeFactory.createReadLocal(scopeEnvironment.getReturnSlot()));
784784
}
785785

786+
SourceSection sourceSection = createSourceSection(node.startOffset, node.endOffset);
787+
returnTarget.assignSourceSection(sourceSection);
788+
789+
scopeEnvironment.setCurrentScope(node.functionScope.getParent());
790+
ExpressionNode[] defaults = node.argBuilder.getDefaultParameterValues(this);
791+
FunctionDefinitionNode.KwDefaultExpressionNode[] kwDefaults = node.argBuilder.getKwDefaultParameterValues(this);
786792
Map<String, SSTNode> sstAnnotations = node.argBuilder.getAnnotatedArgs();
787793
Map<String, ExpressionNode> annotations = null;
788794
if (sstAnnotations != null && !sstAnnotations.isEmpty()) {
@@ -792,12 +798,6 @@ public PNode visit(FunctionDefSSTNode node) {
792798
annotations.put(argName, (ExpressionNode) sstType.accept(this));
793799
}
794800
}
795-
SourceSection sourceSection = createSourceSection(node.startOffset, node.endOffset);
796-
returnTarget.assignSourceSection(sourceSection);
797-
798-
scopeEnvironment.setCurrentScope(node.functionScope.getParent());
799-
ExpressionNode[] defaults = node.argBuilder.getDefaultParameterValues(this);
800-
FunctionDefinitionNode.KwDefaultExpressionNode[] kwDefaults = node.argBuilder.getKwDefaultParameterValues(this);
801801
scopeEnvironment.setCurrentScope(node.functionScope);
802802

803803
/**

0 commit comments

Comments
 (0)