Skip to content

Commit 8a250d8

Browse files
committed
eval() overwrites local sym table by default
1 parent 48b6a8f commit 8a250d8

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

custom_components/pyscript/eval.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2213,12 +2213,14 @@ def completions(self, root):
22132213
words.add(name)
22142214
return words
22152215

2216-
async def eval(self, new_state_vars=None):
2216+
async def eval(self, new_state_vars=None, merge_local=False):
22172217
"""Execute parsed code, with the optional state variables added to the scope."""
22182218
self.exception = None
22192219
self.exception_obj = None
22202220
self.exception_long = None
22212221
if new_state_vars:
2222+
if not merge_local:
2223+
self.local_sym_table = {}
22222224
self.local_sym_table.update(new_state_vars)
22232225
if self.ast:
22242226
try:

custom_components/pyscript/event.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def notify_del(cls, event_type, queue):
7070
async def update(cls, event_type, func_args):
7171
"""Deliver all notifications for an event of the given type."""
7272

73-
_LOGGER.debug("event.update(%s, %s, %s)", event_type, vars, func_args)
73+
_LOGGER.debug("event.update(%s, %s)", event_type, func_args)
7474
if event_type in cls.notify:
7575
for queue in cls.notify[event_type]:
7676
await queue.put(["event", func_args])

tests/test_unit_eval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ async def run_one_test(test_data):
13841384
if ast.get_exception() is not None:
13851385
print(f"Parsing {source} failed: {ast.get_exception()}")
13861386
# print(ast.dump())
1387-
result = await ast.eval({"sym_local": 10})
1387+
result = await ast.eval({"sym_local": 10}, merge_local=True)
13881388
assert result == expect
13891389

13901390

0 commit comments

Comments
 (0)