Skip to content
Myr

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

3 files+16 added−3 removed

modified:src/jinja2/environment.py+11 added-1 removed
391 unmodified lines
392 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 line
403 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 overlayed
3 unmodified lines
415 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.419420 .. 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"]426427 rv = object.__new__(self.__class__)428 rv.__dict__.update(self.__dict__)429 rv.overlayed = True
13 unmodified lines
443 rv.extensions[key] = value.bind(rv)444 if extensions is not missing:445 rv.extensions.update(load_extensions(rv, extensions))446447 if enable_async is not missing:448 rv.is_async = enable_async449450 return _environment_config_check(rv)451452 @property453 def lexer(self) -> Lexer:
1214 unmodified lines
modified:src/jinja2/visitor.py+2 added-2 removed
41 unmodified lines
42 return self.generic_visit(node, *args, **kwargs)4344 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)484950class NodeTransformer(NodeVisitor):51 """Walks the abstract syntax tree and allows modifications of nodes.
41 unmodified lines
modified:CHANGES.rst+3 added
3 unmodified lines
4-------------56Unreleased78- Add parameters to ``Environment.overlay`` to match ``__init__``.9 :issue:`1645`101112Version 3.1.113-------------1415Released 2022-03-25
959 unmodified lines