Skip to content

Commit

Permalink
Merge pull request #415 from malthe/issue-414-import-order
Browse files Browse the repository at this point in the history
Imports must appear first, and produced after processing defines
  • Loading branch information
malthe authored Jan 29, 2024
2 parents 6b4e52f + 75c3fdd commit 6322d8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Changes

In next release ...

-
- Fix a regression where a static symbol would not get correctly
imported.
(`#414 <https://github.com/malthe/chameleon/issues/414>`_)

4.5.1 (2024-01-28)
------------------
Expand Down
8 changes: 4 additions & 4 deletions src/chameleon/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ def visit_Module(self, module) -> AST:

for name, node in self.defines.items():
assignment = Assign(targets=[store(name)], value=node, lineno=None)
preamble.append(assignment)
preamble.append(self.visit(assignment))

imports: list[AST] = []
for value, node in self.imports.items():
stmt: AST

Expand All @@ -183,10 +184,9 @@ def visit_Module(self, module) -> AST:
else:
raise TypeError(value)

preamble.append(stmt)
imports.append(stmt)

preamble = [self.visit(stmt) for stmt in preamble]
return Module(preamble + module.body, ())
return Module(imports + preamble + module.body, ())

def visit_Comment(self, node) -> AST:
self.comments.append(node.text)
Expand Down

0 comments on commit 6322d8c

Please sign in to comment.