Added support for generator_stop

This commit is contained in:
Armin Ronacher 2016-12-27 19:52:43 +01:00
parent b78f2617b0
commit e7e14cf349
2 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,12 @@
Jinja2 Changelog
================
Version 2.9
-----------
- Added support for `generator_stop` on supported Python versions
(Python 3.5 and later)
Version 2.8.1
-------------

View File

@ -38,6 +38,15 @@ if hasattr(dict, 'iteritems'):
else:
dict_item_iter = 'items'
code_features = ['division']
# does this python version support generator stops? (PEP 0479)
try:
exec('from __future__ import generator_stop')
code_features.append('generator_stop')
except SyntaxError:
pass
# does if 0: dummy(x) get us x into the scope?
def unoptimize_before_dead_code():
@ -763,7 +772,7 @@ class CodeGenerator(NodeVisitor):
eval_ctx = EvalContext(self.environment, self.name)
from jinja2.runtime import __all__ as exported
self.writeline('from __future__ import division')
self.writeline('from __future__ import %s' % ', '.join(code_features))
self.writeline('from jinja2.runtime import ' + ', '.join(exported))
if not unoptimize_before_dead_code:
self.writeline('dummy = lambda *x: None')