diff --git a/enaml/core/code_generator.py b/enaml/core/code_generator.py index dc87bafb3..66e7ffcd9 100644 --- a/enaml/core/code_generator.py +++ b/enaml/core/code_generator.py @@ -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 diff --git a/releasenotes.rst b/releasenotes.rst index 2120ad306..536b401b9 100644 --- a/releasenotes.rst +++ b/releasenotes.rst @@ -3,6 +3,10 @@ Enaml Release Notes Dates are written as DD/MM/YYYY +0.17.1 - unreleased +------------------- +- fix possible error in rewrite fast locals when using templates on 3.12 PR #550 + 0.17.0 - 20/11/2023 ------------------- - support for Python 3.12 PR #535 diff --git a/tests/test_template.py b/tests/test_template.py index 7cfeeae97..b58c1987c 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -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 #------------------------------------------------------------------------------