File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed
com.oracle.graal.python.test/src
com/oracle/graal/python/test/interop
com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2019, 2022 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2019, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* The Universal Permissive License (UPL), Version 1.0
@@ -143,7 +143,7 @@ public void testPListRemovable() {
143
143
144
144
@ Test
145
145
public void testIsNull () {
146
- assertTrue (v ("None" ).isNull ());
146
+ assertTrue (v ("[ None]" ). getArrayElement ( 0 ).isNull ());
147
147
}
148
148
149
149
@ Test
Original file line number Diff line number Diff line change @@ -291,6 +291,14 @@ def test_internal_languages_dont_eval():
291
291
292
292
assert polyglot .eval (language = "python" , string = "21 * 2" ) == 42
293
293
294
+ def test_module_eval_returns_last_expr ():
295
+ assert polyglot .eval (language = "python" , string = "x = 2; x" ) == 2
296
+
297
+ def test_module_eval_returns_module ():
298
+ mod = polyglot .eval (language = "python" , string = "x = 2" )
299
+ assert mod .x == 2
300
+ assert type (mod ) == type (sys )
301
+
294
302
@skipIf (is_native , "not supported in native mode" )
295
303
def test_non_index_array_access ():
296
304
import java
Original file line number Diff line number Diff line change @@ -292,19 +292,25 @@ private Object run(VirtualFrame frame) {
292
292
PArguments .setArgument (arguments , i , frame .getArguments ()[i ]);
293
293
}
294
294
PythonContext pythonContext = getContext ();
295
+ PythonModule mainModule = null ;
295
296
if (getSourceSection ().getSource ().isInternal ()) {
296
297
// internal sources are not run in the main module
297
298
PArguments .setGlobals (arguments , pythonContext .factory ().createDict ());
298
299
} else {
299
- PythonModule mainModule = pythonContext .getMainModule ();
300
+ mainModule = pythonContext .getMainModule ();
300
301
PDict mainDict = GetOrCreateDictNode .getUncached ().execute (mainModule );
301
302
PArguments .setGlobals (arguments , mainModule );
302
303
PArguments .setSpecialArgument (arguments , mainDict );
303
304
PArguments .setException (arguments , PException .NO_EXCEPTION );
304
305
}
305
306
Object state = IndirectCalleeContext .enterIndirect (getPythonLanguage (), pythonContext , arguments );
306
307
try {
307
- return innerCallTarget .call (arguments );
308
+ Object result = innerCallTarget .call (arguments );
309
+ if (mainModule != null && result == PNone .NONE ) {
310
+ return mainModule ;
311
+ } else {
312
+ return result ;
313
+ }
308
314
} finally {
309
315
IndirectCalleeContext .exit (getPythonLanguage (), pythonContext , state );
310
316
}
You can’t perform that action at this time.
0 commit comments