diff --git a/django-stubs/template/backends/base.pyi b/django-stubs/template/backends/base.pyi index 5f48ad7..b09ad99 100644 --- a/django-stubs/template/backends/base.pyi +++ b/django-stubs/template/backends/base.pyi @@ -1,6 +1,9 @@ -from typing import Any, Iterator, List, Mapping, Optional, Tuple +from typing import Any, Dict, Iterator, List, Mapping, Optional, Protocol, Tuple, Union -from django.template.base import Template +from django.http.request import HttpRequest +from django.template import TemplateDoesNotExist +from django.template.base import Context +from django.utils.safestring import SafeString class BaseEngine: name: str = ... @@ -9,8 +12,15 @@ class BaseEngine: def __init__(self, params: Mapping[str, Any]) -> None: ... @property def app_dirname(self) -> Optional[str]: ... - def from_string(self, template_code: str) -> Template: ... - def get_template(self, template_name: str) -> Optional[Template]: ... + def from_string(self, template_code: str) -> _EngineTemplate: ... + def get_template(self, template_name: str) -> _EngineTemplate: ... @property def template_dirs(self) -> Tuple[str]: ... def iter_template_filenames(self, template_name: str) -> Iterator[str]: ... + +class _EngineTemplate(Protocol): + def render( + self, + context: Optional[Union[Context, Dict[str, Any]]] = ..., + request: Optional[HttpRequest] = ..., + ) -> SafeString: ... diff --git a/django-stubs/template/loader.pyi b/django-stubs/template/loader.pyi index 507efa5..11e9988 100644 --- a/django-stubs/template/loader.pyi +++ b/django-stubs/template/loader.pyi @@ -4,8 +4,9 @@ from django.http.request import HttpRequest from django.template.exceptions import TemplateDoesNotExist as TemplateDoesNotExist # noqa: F401 from . import engines as engines # noqa: F401 +from .backends.base import _EngineTemplate -def get_template(template_name: str, using: Optional[str] = ...) -> Any: ... +def get_template(template_name: str, using: Optional[str] = ...) -> _EngineTemplate: ... def select_template(template_name_list: Union[Sequence[str], str], using: Optional[str] = ...) -> Any: ... def render_to_string( template_name: Union[Sequence[str], str],