Add type hints to get_undeclared_template_variables

This commit is contained in:
Karol Zlot 2022-06-06 23:49:48 +02:00
parent 2681c4801d
commit 43ceb38465

View File

@ -6,7 +6,7 @@ Created : 2015-03-12
"""
from os import PathLike
from typing import Any, Optional, IO, Union, Dict
from typing import Any, Optional, IO, Union, Dict, Set
from .subdoc import Subdoc
import functools
import io
@ -36,7 +36,7 @@ class DocxTemplate(object):
HEADER_URI = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"
FOOTER_URI = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"
def __init__(self, template_file_or_path: Union[IO[bytes], str, PathLike[str]]):
def __init__(self, template_file_or_path: Union[IO[bytes], str, PathLike[str]]) -> None:
self.template_file_or_path = template_file_or_path
self.reset_replacements()
self.docx = None
@ -324,7 +324,7 @@ class DocxTemplate(object):
new_part.load_rel(rel.reltype, rel._target, rel.rId, rel.is_external)
self.docx._part._rels[relKey]._target = new_part
def render(self, context: Dict[str, Any], jinja_env: Optional[Environment]=None, autoescape: bool=False):
def render(self, context: Dict[str, Any], jinja_env: Optional[Environment]=None, autoescape: bool=False) -> None:
# init template working attributes
self.render_init()
@ -722,7 +722,7 @@ class DocxTemplate(object):
self.post_processing(output_file_or_path)
self.is_saved = True
def get_undeclared_template_variables(self, jinja_env=None):
def get_undeclared_template_variables(self, jinja_env: Optional[Environment]=None) -> Set[str]:
self.init_docx()
xml = self.get_xml()
xml = self.patch_xml(xml)