Skip to content

Commit 99788ec

Browse files
committed
added repeat assignments, and added assert statement
1 parent 2f0995f commit 99788ec

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

custom_components/pyscript/eval.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,9 @@ async def recurse_assign(self, lhs, val):
655655

656656
async def ast_assign(self, arg):
657657
"""Execute assignment statement."""
658-
await self.recurse_assign(arg.targets[0], await self.aeval(arg.value))
658+
rhs = await self.aeval(arg.value)
659+
for target in arg.targets:
660+
await self.recurse_assign(target, rhs)
659661

660662
async def ast_augassign(self, arg):
661663
"""Execute augmented assignment statement (lhs <BinOp>= value)."""
@@ -733,6 +735,13 @@ async def ast_delete(self, arg):
733735
else:
734736
raise NotImplementedError(f"unknown target type {arg1} in del")
735737

738+
async def ast_assert(self, arg):
739+
"""Execute assert statement."""
740+
if not await self.aeval(arg.test):
741+
if arg.msg:
742+
raise AssertionError(await self.aeval(arg.msg))
743+
raise AssertionError
744+
736745
async def ast_attribute_collapse(self, arg):
737746
"""Combine dotted attributes to allow variable names to have dots."""
738747
# collapse dotted names, eg:

custom_components/pyscript/handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def init(hass):
5959
Handler.loggers = {}
6060

6161
async def entity_ids(domain=None):
62+
"""Implement entity_ids."""
6263
return Handler.hass.states.async_entity_ids(domain)
6364

6465
async def async_sleep(duration):

tests/custom_components/pyscript/test_unit_eval.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
[10, 11, 12, 13, 14, 15, 16, 17],
141141
],
142142
["(x, y) = (1, 2); [x, y]", [1, 2]],
143+
["a, b = (x, y) = (1, 2); [a, b, x, y]", [1, 2, 1, 2]],
143144
["y = [1,2]; (x, y[0]) = (3, 4); [x, y]", [3, [4, 2]]],
144145
["((x, y), (z, t)) = ((1, 2), (3, 4)); [x, y, z, t]", [1, 2, 3, 4]],
145146
[
@@ -697,6 +698,11 @@ def test_eval(hass):
697698
"(x, y) = 1",
698699
"Exception in test line 1 column 9: cannot unpack non-iterable object",
699700
],
701+
[
702+
"assert 1 == 0, 'this is an error'",
703+
"Exception in test line 1 column 15: this is an error",
704+
],
705+
["assert 1 == 0", "Exception in test line 1 column 12: "],
700706
[
701707
"import math; math.sinXYZ",
702708
"Exception in test line 1 column 13: module 'math' has no attribute 'sinXYZ'",

0 commit comments

Comments
 (0)