Skip to content

Commit

Permalink
Fix rewrite fast locals on 3.12 for #548
Browse files Browse the repository at this point in the history
  • Loading branch information
frmdstryr committed Apr 15, 2024
1 parent bf0ea6f commit 0b34df4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions enaml/core/code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,14 @@ def rewrite_to_fast_locals(self, local_names):
stored_names = set()
code_ops = self.code_ops
for idx, instr in enumerate(code_ops):
if not isinstance(instr, bc.Instr):
continue
if instr.name == "STORE_NAME":
stored_names.add(instr.arg)
instr.name = "STORE_FAST"
for idx, instr in enumerate(code_ops):
if not isinstance(instr, bc.Instr):
continue
i_name = instr.name
if i_name == "LOAD_NAME":
i_arg = instr.arg
Expand Down
18 changes: 18 additions & 0 deletions tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,24 @@ def test_syntax_20():
compile_source(source, 'Main')


def test_syntax_21():
source = dedent("""\
template Other(*Args):
Slider:
pass
template Main(Model):
const args = [
m for m in Model.members().values()
if isinstance(m, Float)
]
Other(args): *all:
pass
""")
compile_source(source, 'Main')


#------------------------------------------------------------------------------
# Bad Template Syntax
#------------------------------------------------------------------------------
Expand Down

0 comments on commit 0b34df4

Please sign in to comment.