From 21da8f529888a2144bafd183439d26564c6dc134 Mon Sep 17 00:00:00 2001 From: Tom Brouwer Date: Fri, 1 Apr 2022 22:29:09 +0200 Subject: [PATCH 1/2] add missing options to overlay from __init__ --- CHANGES.rst | 3 +++ src/jinja2/environment.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index cec1ad842..da7d0a682 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,9 @@ Version 3.1.2 Unreleased +- Add parameters to ``Environment.overlay`` to match ``__init__``. + :issue:`1645` + Version 3.1.1 ------------- diff --git a/src/jinja2/environment.py b/src/jinja2/environment.py index 9dd455a52..ea04e8b44 100644 --- a/src/jinja2/environment.py +++ b/src/jinja2/environment.py @@ -393,6 +393,8 @@ def overlay( line_comment_prefix: t.Optional[str] = missing, trim_blocks: bool = missing, lstrip_blocks: bool = missing, + newline_sequence: "te.Literal['\\n', '\\r\\n', '\\r']" = missing, + keep_trailing_newline: bool = missing, extensions: t.Sequence[t.Union[str, t.Type["Extension"]]] = missing, optimized: bool = missing, undefined: t.Type[Undefined] = missing, @@ -402,6 +404,7 @@ def overlay( cache_size: int = missing, auto_reload: bool = missing, bytecode_cache: t.Optional["BytecodeCache"] = missing, + enable_async: bool = False, ) -> "Environment": """Create a new overlay environment that shares all the data with the current environment except for cache and the overridden attributes. @@ -413,9 +416,13 @@ def overlay( up completely. Not all attributes are truly linked, some are just copied over so modifications on the original environment may not shine through. + + .. versionchanged:: 3.1.2 + Added the ``newline_sequence``,, ``keep_trailing_newline``, + and ``enable_async`` parameters to match ``__init__``. """ args = dict(locals()) - del args["self"], args["cache_size"], args["extensions"] + del args["self"], args["cache_size"], args["extensions"], args["enable_async"] rv = object.__new__(self.__class__) rv.__dict__.update(self.__dict__) @@ -437,6 +444,9 @@ def overlay( if extensions is not missing: rv.extensions.update(load_extensions(rv, extensions)) + if enable_async is not missing: + rv.is_async = enable_async + return _environment_config_check(rv) @property From 5d3d2414710c1439105d84efc58e4aba8e453cb3 Mon Sep 17 00:00:00 2001 From: David Lord Date: Mon, 4 Apr 2022 06:56:11 -0700 Subject: [PATCH 2/2] fix flake8-bugbear finding --- src/jinja2/visitor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jinja2/visitor.py b/src/jinja2/visitor.py index 71e341e30..17c6aaba5 100644 --- a/src/jinja2/visitor.py +++ b/src/jinja2/visitor.py @@ -43,8 +43,8 @@ def visit(self, node: Node, *args: t.Any, **kwargs: t.Any) -> t.Any: def generic_visit(self, node: Node, *args: t.Any, **kwargs: t.Any) -> t.Any: """Called if no explicit visitor function exists for a node.""" - for node in node.iter_child_nodes(): - self.visit(node, *args, **kwargs) + for child_node in node.iter_child_nodes(): + self.visit(child_node, *args, **kwargs) class NodeTransformer(NodeVisitor):