Skip to content

Commit 7951852

Browse files
numberpicosminbasca
authored andcommitted
fix findLocalsScopes() for null frames, add builtins to top scopes
1 parent 11eac89 commit 7951852

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ protected boolean isObjectOfLanguage(Object object) {
313313
protected Object findMetaObject(PythonContext context, Object value) {
314314
if (value != null) {
315315
if (value instanceof PythonObject) {
316-
return ((PythonObject) value).asPythonClass().getName();
316+
return ((PythonObject) value).asPythonClass();
317317
} else if (value instanceof PythonAbstractObject ||
318318
value instanceof Number ||
319319
value instanceof String ||
@@ -339,14 +339,16 @@ protected Iterable<Scope> findLocalScopes(PythonContext context, Node node, Fram
339339
for (Scope s : super.findLocalScopes(context, node, frame)) {
340340
scopes.add(s);
341341
}
342-
PythonObject globals = PArguments.getGlobals(frame);
343-
if (globals != null) {
344-
scopes.add(Scope.newBuilder("globals()", globals).build());
345-
}
346-
Frame generatorFrame = PArguments.getGeneratorFrame(frame);
347-
if (generatorFrame != null) {
348-
for (Scope s : super.findLocalScopes(context, node, generatorFrame)) {
349-
scopes.add(s);
342+
if (frame != null) {
343+
PythonObject globals = PArguments.getGlobals(frame);
344+
if (globals != null) {
345+
scopes.add(Scope.newBuilder("globals()", globals).build());
346+
}
347+
Frame generatorFrame = PArguments.getGeneratorFrame(frame);
348+
if (generatorFrame != null) {
349+
for (Scope s : super.findLocalScopes(context, node, generatorFrame)) {
350+
scopes.add(s);
351+
}
350352
}
351353
}
352354
return scopes;
@@ -356,6 +358,7 @@ protected Iterable<Scope> findLocalScopes(PythonContext context, Node node, Fram
356358
protected Iterable<Scope> findTopScopes(PythonContext context) {
357359
ArrayList<Scope> scopes = new ArrayList<>();
358360
scopes.add(Scope.newBuilder("__main__", context.getMainModule()).build());
361+
scopes.add(Scope.newBuilder("builtins", context.getBuiltins()).build());
359362
return scopes;
360363
}
361364

0 commit comments

Comments
 (0)