Remove 'Implicit Async', Don't Await runtime.run() (#928)

* Revert to runPython instead of await runPythonAsync

* "Implicit Coroutines" are no longer permitted in py-script tags

* Tests added for the above

* xfail test_importmap (See #938)
This commit is contained in:
Jeff Glass
2022-11-16 13:11:40 -06:00
committed by GitHub
parent 41ebaaf366
commit 0b23310a06
17 changed files with 318 additions and 74 deletions

View File

@@ -1,3 +1,4 @@
import ast
import asyncio
import base64
import html
@@ -404,4 +405,28 @@ class PyListTemplate:
pass
class TopLevelAsyncFinder(ast.NodeVisitor):
def is_source_top_level_await(self, source):
self.async_found = False
node = ast.parse(source)
self.generic_visit(node)
return self.async_found
def visit_Await(self, node):
self.async_found = True
def visit_AsyncFor(self, node):
self.async_found = True
def visit_AsyncWith(self, node):
self.async_found = True
def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef):
pass # Do not visit children of async function defs
def uses_top_level_await(source: str) -> bool:
return TopLevelAsyncFinder().is_source_top_level_await(source)
pyscript = PyScript()