mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 10:47:35 -05:00
Improve typing on PyScriptTag (#1135)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { Plugin } from "../plugin";
|
||||
import { TargetedStdio, StdioMultiplexer } from "../stdio";
|
||||
import type { Interpreter } from "../interpreter";
|
||||
import { make_PyScript } from "../components/pyscript";
|
||||
|
||||
type PyScriptTag = InstanceType<ReturnType<typeof make_PyScript>>;
|
||||
|
||||
/**
|
||||
* The StdioDirector plugin captures the output to Python's sys.stdio and
|
||||
@@ -25,7 +27,7 @@ export class StdioDirector extends Plugin {
|
||||
* with that ID for the duration of the evaluation.
|
||||
*
|
||||
*/
|
||||
beforePyScriptExec(options: {interpreter: Interpreter, src: string, pyScriptTag: any}): void {
|
||||
beforePyScriptExec(options: {interpreter: Interpreter, src: string, pyScriptTag: PyScriptTag}): void {
|
||||
if (options.pyScriptTag.hasAttribute("output")){
|
||||
const targeted_io = new TargetedStdio(options.pyScriptTag, "output", true, true)
|
||||
options.pyScriptTag.stdout_manager = targeted_io
|
||||
@@ -41,7 +43,7 @@ export class StdioDirector extends Plugin {
|
||||
/** After a <py-script> tag is evaluated, if that tag has a 'stdout_manager'
|
||||
* (presumably TargetedStdio, or some other future IO handler), it is removed.
|
||||
*/
|
||||
afterPyScriptExec(options: {interpreter: Interpreter, src: string, pyScriptTag: any, result: any}): void {
|
||||
afterPyScriptExec(options: {interpreter: Interpreter, src: string, pyScriptTag: PyScriptTag, result: any}): void {
|
||||
if (options.pyScriptTag.stdout_manager != null){
|
||||
this._stdioMultiplexer.removeListener(options.pyScriptTag.stdout_manager)
|
||||
options.pyScriptTag.stdout_manager = null
|
||||
|
||||
Reference in New Issue
Block a user