mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-14 07:47:09 +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:
|
class BaseEngine:
|
||||||
name: str = ...
|
name: str = ...
|
||||||
@@ -9,8 +12,15 @@ class BaseEngine:
|
|||||||
def __init__(self, params: Mapping[str, Any]) -> None: ...
|
def __init__(self, params: Mapping[str, Any]) -> None: ...
|
||||||
@property
|
@property
|
||||||
def app_dirname(self) -> Optional[str]: ...
|
def app_dirname(self) -> Optional[str]: ...
|
||||||
def from_string(self, template_code: str) -> Template: ...
|
def from_string(self, template_code: str) -> _EngineTemplate: ...
|
||||||
def get_template(self, template_name: str) -> Optional[Template]: ...
|
def get_template(self, template_name: str) -> _EngineTemplate: ...
|
||||||
@property
|
@property
|
||||||
def template_dirs(self) -> Tuple[str]: ...
|
def template_dirs(self) -> Tuple[str]: ...
|
||||||
def iter_template_filenames(self, template_name: str) -> Iterator[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 django.template.exceptions import TemplateDoesNotExist as TemplateDoesNotExist # noqa: F401
|
||||||
|
|
||||||
from . import engines as engines # 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 select_template(template_name_list: Union[Sequence[str], str], using: Optional[str] = ...) -> Any: ...
|
||||||
def render_to_string(
|
def render_to_string(
|
||||||
template_name: Union[Sequence[str], str],
|
template_name: Union[Sequence[str], str],
|
||||||
|
|||||||
Reference in New Issue
Block a user