Coverage for kwai/core/template/jinja2_template.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-09-05 17:55 +0000

1"""Module that implements the Template interface for a jinja2 template.""" 

2from typing import Any 

3 

4import jinja2 

5 

6from .template import Template 

7 

8 

9class Jinja2Template(Template): 

10 """A jinja2 template.""" 

11 

12 def __init__(self, template: jinja2.Template, **kwargs: dict[str, Any]): 

13 """Construct a new template. 

14 

15 kwargs will be merged with the variables used in render. 

16 """ 

17 self._template = template 

18 self._variables = kwargs 

19 

20 def render(self, **kwargs: dict[str, Any]) -> str: 

21 """Render the template.""" 

22 return self._template.render(kwargs | self._variables)