@@ -313,7 +313,7 @@ protected boolean isObjectOfLanguage(Object object) {
313
313
protected Object findMetaObject (PythonContext context , Object value ) {
314
314
if (value != null ) {
315
315
if (value instanceof PythonObject ) {
316
- return ((PythonObject ) value ).asPythonClass (). getName () ;
316
+ return ((PythonObject ) value ).asPythonClass ();
317
317
} else if (value instanceof PythonAbstractObject ||
318
318
value instanceof Number ||
319
319
value instanceof String ||
@@ -339,14 +339,16 @@ protected Iterable<Scope> findLocalScopes(PythonContext context, Node node, Fram
339
339
for (Scope s : super .findLocalScopes (context , node , frame )) {
340
340
scopes .add (s );
341
341
}
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
+ }
350
352
}
351
353
}
352
354
return scopes ;
@@ -356,6 +358,7 @@ protected Iterable<Scope> findLocalScopes(PythonContext context, Node node, Fram
356
358
protected Iterable <Scope > findTopScopes (PythonContext context ) {
357
359
ArrayList <Scope > scopes = new ArrayList <>();
358
360
scopes .add (Scope .newBuilder ("__main__" , context .getMainModule ()).build ());
361
+ scopes .add (Scope .newBuilder ("builtins" , context .getBuiltins ()).build ());
359
362
return scopes ;
360
363
}
361
364
0 commit comments