8000 Revert output manager after REPR evaluation (#522) · cm2solutions/pyscript@deb2eee · GitHub
[go: up one dir, main page]

Skip to content

Commit deb2eee

Browse files
authored
Revert output manager after REPR evaluation (pyscript#522)
* Revert output manager after repr evaluation * Fix indentation
1 parent 829cc9f commit deb2eee

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pyscriptjs/src/components/base.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,19 @@ export class BaseEvalElement extends HTMLElement {
130130
try {
131131
source = this.source ? await this.getSourceFromFile(this.source)
132132
: this.getSourceFromElement();
133+
const is_async = source.includes('asyncio')
133134

134135
await this._register_esm(pyodide);
135-
136-
if (source.includes('asyncio')) {
136+
if (is_async) {
137137
await pyodide.runPythonAsync(
138138
`output_manager.change(out="${this.outputElement.id}", err="${this.errorElement.id}", append=${this.appendOutput ? 'True' : 'False'})`,
139139
);
140140
output = await pyodide.runPythonAsync(source);
141-
await pyodide.runPythonAsync(`output_manager.revert()`);
142141
} else {
143142
output = pyodide.runPython(
144143
`output_manager.change(out="${this.outputElement.id}", err="${this.errorElement.id}", append=${this.appendOutput ? 'True' : 'False'})`,
145144
);
146145
output = pyodide.runPython(source);
147-
pyodide.runPython(`output_manager.revert()`);
148146
}
149147

150148
if (output !== undefined) {
@@ -158,6 +156,12 @@ export class BaseEvalElement extends HTMLElement {
158156
this.outputElement.style.display = 'block';
159157
}
160158

159+
if (is_async) {
160+
await pyodide.runPythonAsync(`output_manager.revert()`);
161+
} else {
162+
await pyodide.runPython(`output_manager.revert()`);
163+
}
164+
161165
// check if this REPL contains errors, delete them and remove error classes
162166
const errorElements = document.querySelectorAll(`div[id^='${this.errorElement.id}'][error]`);
163167
if (errorElements.length > 0) {

0 commit comments

Comments
 (0)
0