From 1259162c99055400548fe2d6762080aaef2e24f0 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Wed, 28 Dec 2016 15:19:32 +0100 Subject: [PATCH] Use more _get_default_module calls --- jinja2/compiler.py | 9 +++++---- jinja2/environment.py | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/jinja2/compiler.py b/jinja2/compiler.py index e2e682c4..1d9d5059 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -971,10 +971,11 @@ class CodeGenerator(NodeVisitor): self.writeline('else:') self.indent() + loop = self.environment._async and 'async for' or 'for' if node.with_context: - self.writeline('for event in template.root_render_func(' + self.writeline('%s event in template.root_render_func(' 'template.new_context(context.parent, True, ' - 'locals())):') + 'locals())):' % loop) else: self.writeline('for event in template._get_default_module()' '._body_stream:') @@ -999,7 +1000,7 @@ class CodeGenerator(NodeVisitor): if node.with_context: self.write('make_module(context.parent, True, locals())') else: - self.write('module') + self.write('_get_default_module()') if frame.toplevel and not node.target.startswith('_'): self.writeline('context.exported_vars.discard(%r)' % node.target) frame.assigned_names.add(node.target) @@ -1013,7 +1014,7 @@ class CodeGenerator(NodeVisitor): if node.with_context: self.write('make_module(context.parent, True)') else: - self.write('module') + self.write('_get_default_module()') var_names = [] discarded_names = [] diff --git a/jinja2/environment.py b/jinja2/environment.py index c7dc6422..f91b01dc 100644 --- a/jinja2/environment.py +++ b/jinja2/environment.py @@ -1097,7 +1097,9 @@ class TemplateModule(object): if body_stream is None: if context.environment._async: raise RuntimeError('Async mode requires a body stream ' - 'to be passed in.') + 'to be passed to a template module. Use ' + 'the async methods of the API you are ' + 'using.') body_stream = list(template.root_render_func(context)) self._body_stream = body_stream self.__dict__.update(context.get_exported()) -- 2.47.2