Improve typing on PyScriptTag (#1135)

This commit is contained in:
Jeff Glass
2023-01-26 09:38:07 -06:00
committed by GitHub
parent 12bf6db331
commit a210b2d5f5
2 changed files with 10 additions and 6 deletions

View File

@@ -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