From 2c49d14ceca875ae7ae6631bef5b37519137c24e Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Tue, 6 Feb 2018 21:52:57 +0900 Subject: [PATCH] Lazy asyncsupport.patch_all() fixes #765 --- jinja2/__init__.py | 11 ----------- jinja2/asyncsupport.py | 3 +++ jinja2/environment.py | 2 ++ 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/jinja2/__init__.py b/jinja2/__init__.py index 817d4e8a..f20c573f 100644 --- a/jinja2/__init__.py +++ b/jinja2/__init__.py @@ -70,14 +70,3 @@ __all__ = [ '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 diff --git a/jinja2/asyncsupport.py b/jinja2/asyncsupport.py index b1e7b5ce..53ad192d 100644 --- a/jinja2/asyncsupport.py +++ b/jinja2/asyncsupport.py @@ -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() diff --git a/jinja2/environment.py b/jinja2/environment.py index 549d9afa..295ff13e 100644 --- a/jinja2/environment.py +++ b/jinja2/environment.py @@ -334,6 +334,8 @@ class Environment(object): 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) -- 2.47.3