Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe committed Jan 16, 2024
1 parent 118c40f commit 6b9f0c3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/chameleon/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
from chameleon.utils import value_repr


PROGRAM_NAME = "initialize"


if TYPE_CHECKING:
from _typeshed import StrPath
from abc import abstractmethod
Expand Down Expand Up @@ -199,8 +202,8 @@ def cook(self, body: str) -> None:
digest = self.digest(body, names)
program = self._cook(body, digest, names)

initialize = program['initialize']
functions = initialize(*builtins)
init = program[PROGRAM_NAME]
functions = init(*builtins)

for name, function in functions.items():
setattr(self, "_" + name, function)
Expand Down Expand Up @@ -330,7 +333,7 @@ def digest(self, body: str, names: Collection[str]) -> str:

def _compile(self, body: str, builtins: Collection[str]) -> str:
program = self.parse(body)
module = Module("initialize", program)
module = Module(PROGRAM_NAME, program)
compiler = Compiler(
self.engine, module, str(self.filename), body,
builtins, strict=self.strict
Expand Down

0 comments on commit 6b9f0c3

Please sign in to comment.