Skip to content

Commit 7a8efe6

Browse files
committed
mark all values as invisible in interactive eval and print them ourselves using repr
1 parent 4c55b01 commit 7a8efe6

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.graalvm.options.OptionDescriptors;
3535

3636
import com.oracle.graal.python.builtins.Python3Core;
37-
import com.oracle.graal.python.builtins.objects.PNone;
3837
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
3938
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
4039
import com.oracle.graal.python.builtins.objects.function.PArguments;
@@ -329,7 +328,7 @@ public static PythonCore getCore() {
329328

330329
@Override
331330
protected boolean isVisible(PythonContext context, Object value) {
332-
return value != PNone.NONE && value != PNone.NO_VALUE;
331+
return false;
333332
}
334333

335334
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/TopLevelExceptionHandler.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@
4141
package com.oracle.graal.python.nodes.control;
4242

4343
import static com.oracle.graal.python.nodes.SpecialMethodNames.__STR__;
44+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REPR__;
4445
import static com.oracle.graal.python.runtime.exception.PythonErrorType.SystemExit;
4546

4647
import java.io.IOException;
48+
import java.io.OutputStream;
49+
import java.nio.charset.StandardCharsets;
4750

4851
import com.oracle.graal.python.PythonLanguage;
4952
import com.oracle.graal.python.builtins.objects.PNone;
@@ -81,6 +84,7 @@ public class TopLevelExceptionHandler extends RootNode {
8184

8285
@Child private CreateArgumentsNode createArgs = CreateArgumentsNode.create();
8386
@Child private LookupAndCallUnaryNode callStrNode = LookupAndCallUnaryNode.create(__STR__);
87+
@Child private LookupAndCallUnaryNode callReprNode = LookupAndCallUnaryNode.create(__REPR__);
8488
@Child private CallNode callNode = CallNode.create();
8589

8690
public TopLevelExceptionHandler(PythonLanguage language, RootNode child) {
@@ -106,8 +110,9 @@ public Object execute(VirtualFrame frame) {
106110
return null;
107111
} else {
108112
assert context.get().getCurrentException() == null;
113+
Object result;
109114
try {
110-
return run(frame);
115+
result = run(frame);
111116
} catch (PException e) {
112117
printExc(e);
113118
return null;
@@ -120,6 +125,23 @@ public Object execute(VirtualFrame frame) {
120125
}
121126
throw e;
122127
}
128+
if (getSourceSection().getSource().isInteractive()) {
129+
printResult(result);
130+
}
131+
return result;
132+
}
133+
}
134+
135+
@TruffleBoundary
136+
private void printResult(Object result) {
137+
OutputStream out = getCurrentContext(PythonLanguage.class).getStandardOut();
138+
String stringResult = callReprNode.executeObject(result).toString();
139+
try {
140+
out.write(stringResult.getBytes(StandardCharsets.UTF_8));
141+
out.write(System.getProperty("line.separator").getBytes(StandardCharsets.UTF_8));
142+
} catch (IOException ioex) {
143+
// out stream has problems.
144+
throw new IllegalStateException(ioex);
123145
}
124146
}
125147

0 commit comments

Comments
 (0)