Fix #1841 - Provide a better error when input is used (#1857)

This commit is contained in:
Andrea Giammarchi
2023-11-14 15:25:17 +01:00
committed by GitHub
parent e750fa7393
commit 48e3383f66
3 changed files with 48 additions and 1 deletions

View File

@@ -45,6 +45,19 @@ export const createFunction = (self, name) => {
const SetFunction = typedSet({ typeof: "function" });
const SetString = typedSet({ typeof: "string" });
const inputFailure = `
import builtins
def input(prompt=""):
raise Exception("\\n ".join([
"input() doesn't work when PyScript runs in the main thread.",
"Consider using the worker attribute: https://docs.pyscript.net/2023.11.1/user-guide/workers/"
]))
builtins.input = input
del builtins
del input
`;
export const hooks = {
main: {
/** @type {Set<function>} */
@@ -60,7 +73,7 @@ export const hooks = {
/** @type {Set<function>} */
onAfterRunAsync: new SetFunction(),
/** @type {Set<string>} */
codeBeforeRun: new SetString(),
codeBeforeRun: new SetString([inputFailure]),
/** @type {Set<string>} */
codeBeforeRunAsync: new SetString(),
/** @type {Set<string>} */