mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user