mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-10 14:01:56 +08:00
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:
@@ -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: ...
|
||||
|
||||
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user