Skip to content

Commit 25416bd

Browse files
committed
don't skip await in aeval(); see #710
1 parent f12faaf commit 25416bd

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

custom_components/pyscript/eval.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -931,18 +931,14 @@ async def ast_not_implemented(self, arg, *args):
931931
name = "ast_" + arg.__class__.__name__.lower()
932932
raise NotImplementedError(f"{self.name}: not implemented ast " + name)
933933

934-
async def aeval(self, arg, undefined_check=True, do_await=True):
934+
async def aeval(self, arg, undefined_check=True):
935935
"""Vector to specific function based on ast class type."""
936936
name = "ast_" + arg.__class__.__name__.lower()
937937
try:
938938
if hasattr(arg, "lineno"):
939939
self.lineno = arg.lineno
940940
self.col_offset = arg.col_offset
941-
val = (
942-
await getattr(self, name, self.ast_not_implemented)(arg)
943-
if do_await
944-
else getattr(self, name, self.ast_not_implemented)(arg)
945-
)
941+
val = await getattr(self, name, self.ast_not_implemented)(arg)
946942
if undefined_check and isinstance(val, EvalName):
947943
raise NameError(f"name '{val.name}' is not defined")
948944
return val
@@ -2025,7 +2021,7 @@ async def ast_formattedvalue(self, arg):
20252021

20262022
async def ast_await(self, arg):
20272023
"""Evaluate await expr."""
2028-
coro = await self.aeval(arg.value, do_await=False)
2024+
coro = await self.aeval(arg.value)
20292025
if coro and asyncio.iscoroutine(coro):
20302026
return await coro
20312027
return coro

tests/test_unit_eval.py

+16
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,22 @@ async def run():
14561456
""",
14571457
"done",
14581458
],
1459+
[
1460+
"""
1461+
class Test:
1462+
def __init__(self, value):
1463+
self.val = value
1464+
1465+
async def getval(self):
1466+
async def handler():
1467+
return self.val
1468+
return handler()
1469+
1470+
t = Test(20)
1471+
[await(await t.getval()), t.getval()]
1472+
""",
1473+
[20, 20],
1474+
],
14591475
]
14601476

14611477

0 commit comments

Comments
 (0)