mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:54:42 +00:00
[playground] Fix reveal_type
(#17013)
## Summary Capture both `stdout` and `stderr` in a single stream. This fixes `reveal_type`, which prints to `stderr` by default. ## Test Plan Tested with a simple `reveal_type(1)` example and got the output: ``` Runtime value is '1' Runtime type is 'int' ```
This commit is contained in:
parent
6ef522159d
commit
142fe0d29b
1 changed files with 9 additions and 8 deletions
|
@ -134,13 +134,14 @@ function RunWithPyiodide({
|
||||||
|
|
||||||
if (output == null) {
|
if (output == null) {
|
||||||
const handleRun = () => {
|
const handleRun = () => {
|
||||||
let stdout = "";
|
let combined_output = "";
|
||||||
|
|
||||||
pyodide.setStdout({
|
const outputHandler = (output: string) => {
|
||||||
batched(output) {
|
combined_output += output + "\n";
|
||||||
stdout += output + "\n";
|
};
|
||||||
},
|
|
||||||
});
|
pyodide.setStdout({ batched: outputHandler });
|
||||||
|
pyodide.setStderr({ batched: outputHandler });
|
||||||
|
|
||||||
const main = files.selected == null ? "" : files.contents[files.selected];
|
const main = files.selected == null ? "" : files.contents[files.selected];
|
||||||
|
|
||||||
|
@ -163,7 +164,7 @@ function RunWithPyiodide({
|
||||||
|
|
||||||
def reveal_type(obj):
|
def reveal_type(obj):
|
||||||
import typing
|
import typing
|
||||||
print(f"Runtime value is: \`{obj}\`")
|
print(f"Runtime value is '{obj}'")
|
||||||
return typing.reveal_type(obj)
|
return typing.reveal_type(obj)
|
||||||
|
|
||||||
builtins.reveal_type = reveal_type`);
|
builtins.reveal_type = reveal_type`);
|
||||||
|
@ -174,7 +175,7 @@ function RunWithPyiodide({
|
||||||
filename: fileName,
|
filename: fileName,
|
||||||
});
|
});
|
||||||
|
|
||||||
setOutput(stdout);
|
setOutput(combined_output);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setOutput(`Failed to run Python script: ${e}`);
|
setOutput(`Failed to run Python script: ${e}`);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue