Closed
Description
Try this in the current build (1):
# foo.py
x = 1
<!-- index.html -->
<script type="py" src="foo.py">
</script>
<script type="py">
print(x)
</script>
This breaks, with NameError: name 'x' is not defined
.
I would have expected the scripts to run in DOM order per-type, regardless of whether they used src
or not,
Things that do Work
(2) Using inline before src
(WORKS)
# bar.py
print(x)
<script type="py">
x = 1
</script>
<script type="py" src="bar.py">
</script>
(3) Neither uses src
(WORKS)
<script type="py">
x = 1
</script>
<script type="py">
print(x)
</script>
(4) Both use src
(WORKS)
# one.py
x = 1
# two.py
print(x)
<script type="py" src="one.py"></script>
<script type="py" src="two.py"></script>
Using MicroPython (5)
All four of the samples above (the broken one and the ones which work) show the same behavior using script type='mpy'
instead of py
.
PolyScript (6)
Doing the following in pure Polyscript works fine, so I think it's an issue in PyScript specifically?
# foo.py
x = 1
<script type="pyodide" src="foo.py"></script>
<script type="pyodide">
print(x)
</script>