Skip to content

Commit

Permalink
🧹 Address feedback in #5933 (#5942)
Browse files Browse the repository at this point in the history
Addresses a comment by @jpelay in this review: #5933

Fixes #5749

**How to test**
All automatic tests should pass
  • Loading branch information
boryanagoncharenko authored Nov 15, 2024
1 parent b165ef0 commit 35104bf
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions hedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2314,10 +2314,10 @@ def if_pressed_without_else(self, meta, args):
def if_pressed_else(self, meta, args):
key = self.process_arg_for_data_access(args[0], meta.line)

if_code = self.if_pressed_code_prepend_global_vars(args[1])
if_code = args[1]
if_function_name = self.make_function_name(args[0], meta.line)

else_code = self.if_pressed_code_prepend_global_vars(args[2])
else_code = args[2]
else_function_name = self.make_function_name('else', meta.line)

return (
Expand All @@ -2329,24 +2329,6 @@ def if_pressed_else(self, meta, args):
self.make_extension_call()
)

def if_pressed_code_prepend_global_vars(self, lines):
""" Combines if_pressed arguments into a code snippet, which will be placed inside a function. To allow
assigning and reassigning variables, all lookup entries, except for funcs and list access, are marked as
global and prepended to the snippet. For example:
points = 5
def if_pressed():
global points <-- without this line, we get an error
points = points + 1
"""
lines = lines if isinstance(lines, list) else [lines]
# variables = [e.name for e in self.lookup.get_only_vars()]
# if variables and lines:
# variables = sorted(list(set(variables)))
# global_vars = f"global {', '.join(variables)}"
# lines.insert(0, global_vars)

return '\n'.join(lines)


@v_args(meta=True)
@hedy_transpiler(level=6)
Expand Down Expand Up @@ -2668,7 +2650,7 @@ def if_pressed(self, meta, args):
key = self.process_arg_for_data_access(args[0], meta.line)
args = [a for a in args if a != ""] # filter out in|dedent tokens

if_code = self.if_pressed_code_prepend_global_vars(args[1:])
if_code = '\n'.join(args[1:])
if_function_name = self.make_function_name(args[0], meta.line)

return (
Expand All @@ -2679,7 +2661,7 @@ def if_pressed(self, meta, args):

def if_pressed_elses(self, meta, args):
args = [a for a in args if a != ""] # filter out in|dedent tokens
else_code = self.if_pressed_code_prepend_global_vars(args)
else_code = '\n'.join(args)
else_function_name = self.make_function_name('else', meta.line)

return (
Expand Down Expand Up @@ -3303,7 +3285,7 @@ def if_pressed_elifs(self, meta, args):
args = [a for a in args if a != ""] # filter out in|dedent tokens
key = self.process_arg_for_data_access(args[0], meta.line)

elif_code = self.if_pressed_code_prepend_global_vars(args[1:])
elif_code = '\n'.join(args[1:])
elif_function_name = self.make_function_name(args[0], meta.line)

return (
Expand Down

0 comments on commit 35104bf

Please sign in to comment.