Skip to content

Commit

Permalink
Merge pull request #806 from methane/lazy-async-patch
Browse files Browse the repository at this point in the history
Lazy asyncsupport.patch_all()
  • Loading branch information
davidism committed Feb 6, 2018
2 parents c0c3b78 + 989a7db commit 041b738
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. currentmodule:: jinja2

Jinja Changelog
===============

Expand All @@ -7,6 +9,12 @@ Version 2.11

unreleased

- Async support is only loaded the first time an
:class:`~environment.Environment` enables it, in order to avoid a
slow initial import. (`#765`_)

.. _#765: https://github.com/pallets/jinja/issues/765


Version 2.10
------------
Expand Down
6 changes: 2 additions & 4 deletions docs/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1309,11 +1309,9 @@ The general syntax is ``<do something> if <something is true> else <do
something else>``.

The `else` part is optional. If not provided, the else block implicitly
evaluates into an undefined object:
evaluates into an undefined object::

.. sourcecode:: jinja

{{ '[%s]' % page.title if page.title }}
{{ ('[%s]' % page.title) if page.title }}


.. _builtin-filters:
Expand Down
11 changes: 0 additions & 11 deletions jinja2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,3 @@
'evalcontextfilter', 'evalcontextfunction', 'make_logging_undefined',
'select_autoescape',
]


def _patch_async():
from jinja2.utils import have_async_gen
if have_async_gen:
from jinja2.asyncsupport import patch_all
patch_all()


_patch_async()
del _patch_async
3 changes: 3 additions & 0 deletions jinja2/asyncsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,6 @@ async def make_async_loop_context(iterable, undefined, recurse=None, depth0=0):
after = _last_iteration
return AsyncLoopContext(async_iterator, undefined, after, length, recurse,
depth0)


patch_all()
2 changes: 2 additions & 0 deletions jinja2/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ def __init__(self,

self.enable_async = enable_async
self.is_async = self.enable_async and have_async_gen
if self.is_async:
import jinja2.asyncsupport # runs patch_all() once

_environment_sanity_check(self)

Expand Down

0 comments on commit 041b738

Please sign in to comment.