Improved type of template.loader.get_template() (#1011)

* Improved type of template.loader.get_template()

* Removed Optional from return type.

* Edits.
This commit is contained in:
David Smith
2022-06-26 22:48:10 +01:00
committed by GitHub
parent 1a29ad4f97
commit 926661ab4a
2 changed files with 16 additions and 5 deletions

View File

@@ -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: ...

View File

@@ -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],