Merge pull request #1647 from Tom-Brouwer/202204/add-missing-overlay-options
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add missing environment options to the Environment.overlay method
authored by David Lord · committed by GitHub · parents ea69e41, 5d3d241 · Browse files · 3 files·+16 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+16 added−3 removed
- other:+16 added−3 removed
Provenance
- Commit
990602f- Tree
664012f- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
ea69e41- Parent 2
5d3d241
3 files changed+16 added−3 removed
modified:src/jinja2/environment.py+11 added-1 removed
391 unmodified lines392 line_statement_prefix: t.Optional[str] = missing,393 line_comment_prefix: t.Optional[str] = missing,394 trim_blocks: bool = missing,395 lstrip_blocks: bool = missing,396+ newline_sequence: "te.Literal['\\n', '\\r\\n', '\\r']" = missing,397+ keep_trailing_newline: bool = missing,398 extensions: t.Sequence[t.Union[str, t.Type["Extension"]]] = missing,399 optimized: bool = missing,400 undefined: t.Type[Undefined] = missing,401 finalize: t.Optional[t.Callable[..., t.Any]] = missing,1 unmodified line403 loader: t.Optional["BaseLoader"] = missing,404 cache_size: int = missing,405 auto_reload: bool = missing,406 bytecode_cache: t.Optional["BytecodeCache"] = missing,407+ enable_async: bool = False,408 ) -> "Environment":409 """Create a new overlay environment that shares all the data with the410 current environment except for cache and the overridden attributes.411 Extensions cannot be removed for an overlayed environment. An overlayed3 unmodified lines415 Creating overlays should happen after the initial environment was set416 up completely. Not all attributes are truly linked, some are just417 copied over so modifications on the original environment may not shine418 through.419+420+ .. versionchanged:: 3.1.2421+ Added the ``newline_sequence``,, ``keep_trailing_newline``,422+ and ``enable_async`` parameters to match ``__init__``.423 """424 args = dict(locals())418- del args["self"], args["cache_size"], args["extensions"]425+ del args["self"], args["cache_size"], args["extensions"], args["enable_async"]426 427 rv = object.__new__(self.__class__)428 rv.__dict__.update(self.__dict__)429 rv.overlayed = True13 unmodified lines443 rv.extensions[key] = value.bind(rv)444 if extensions is not missing:445 rv.extensions.update(load_extensions(rv, extensions))446 447+ if enable_async is not missing:448+ rv.is_async = enable_async449+450 return _environment_config_check(rv)451 452 @property453 def lexer(self) -> Lexer:1214 unmodified linesmodified:src/jinja2/visitor.py+2 added-2 removed
41 unmodified lines42 return self.generic_visit(node, *args, **kwargs)43 44 def generic_visit(self, node: Node, *args: t.Any, **kwargs: t.Any) -> t.Any:45 """Called if no explicit visitor function exists for a node."""46- for node in node.iter_child_nodes():47- self.visit(node, *args, **kwargs)46+ for child_node in node.iter_child_nodes():47+ self.visit(child_node, *args, **kwargs)48 49 50 class NodeTransformer(NodeVisitor):51 """Walks the abstract syntax tree and allows modifications of nodes.41 unmodified linesmodified:CHANGES.rst+3 added
3 unmodified lines4 -------------5 6 Unreleased7 8+- Add parameters to ``Environment.overlay`` to match ``__init__``.9+ :issue:`1645`10 11+12 Version 3.1.113 -------------14 15 Released 2022-03-25959 unmodified lines