You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the state persists in the Pyodide instance, we should implement del or import builtins; builtins.max = max in the test runner's teardown to ensure the global scope is reset between exercises.
Instead of relying on manual del or builtins restoration, we should run each test case in a clean Pyodide.runPython context or use a dedicated namespace dictionary to prevent the global scope pollution entirely.
Using a dedicated namespace dictionary as suggested by opulentgrip is the right direction, but we also need to ensure that the __builtins__ reference is properly isolated to prevent students from inadvertently overriding global functions like max. Are we currently passing a custom dictionary to the globals parameter in pyodide.runPython for every execution, or is there a shared state leaking through the default context?
Activity
walter201230 commentedon Sep 3, 2026
@hehaiyang660-ui 感谢反馈,这题的判分异常已修复部署 🙏 抱歉回复晚了。
与 #296 / #301 是同一个根因。
根因:上一道题的变量污染了下一道题
网站用一个 Pyodide 实例跑所有练习,但从来不清理运行环境。新手很容易把内置函数名当变量用,比如:
这一行跑过之后,
max在本次会话里就不再是那个内置函数了。等你做到后面用max(...)的题,连标准答案都跑不通——报的还是看不懂的错。刷新页面就恢复正常,因为实例被重建了。修法
练习判分改成隔离命名空间:每道题都在全新的环境里跑,跑完即销毁,互不影响。教学代码块(那些「▶ 试运行」)保持原样共享环境,因为它们本来就设计成前后累积(前一块
import re,后一块直接用)。具体到
07-tuple-ops:这题要用max(t),只要你在本次会话里的任何一道前面的题写过max = ...,这题就必挂,且复制标准答案也一样挂。同一批还修了报错提示,以前只显示「代码报错:PythonError」,现在会显示真正的原因。
麻烦强制刷新(Windows
Ctrl + F5,MacCmd + Shift + R)再试。yhdhvyfhv commentedon Sep 18, 2026
Since the state persists in the Pyodide instance, we should implement
delorimport builtins; builtins.max = maxin the test runner's teardown to ensure the global scope is reset between exercises.opulentgrip commentedon Sep 20, 2026
Instead of relying on manual
delorbuiltinsrestoration, we should run each test case in a cleanPyodide.runPythoncontext or use a dedicated namespace dictionary to prevent the global scope pollution entirely.erlenekalafo commentedon Oct 1, 2026
Executing each exercise with a fresh globals dictionary via `pyodide.runPython(code, { globals: py
emmettmorin commentedon Oct 5, 2026
Using a dedicated namespace dictionary as suggested by opulentgrip is the right direction, but we also need to ensure that the
__builtins__reference is properly isolated to prevent students from inadvertently overriding global functions likemax. Are we currently passing a custom dictionary to theglobalsparameter inpyodide.runPythonfor every execution, or is there a shared state leaking through the default context?