Skip to content

Commit cdf62dd

Browse files
authored
Improve django.template (typeddjango#210)
- `django.template.loader.get_template` returns `django.template.base.Template`. - `django.template.loader.select_template` returns `django.template.base.Template`. - `django.template.utils.EngineHandler.__iter__` returns an iterator of `django.template.backends.base.BaseEngine`. - `django.template.utils.get_app_template_dirs` returns a tuple of `pathlib.Path`.
1 parent d44899f commit cdf62dd

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

django-stubs/template/loader.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
from typing import Any
22

33
from django.http.request import HttpRequest
4+
from django.template.base import Template
45
from django.template.exceptions import ( # noqa: F401
56
TemplateDoesNotExist as TemplateDoesNotExist,
67
)
78

89
from . import engines as engines # noqa: F401
910

10-
def get_template(template_name: str, using: str | None = ...) -> Any: ...
11+
def get_template(template_name: str, using: str | None = ...) -> Template: ...
1112
def select_template(
1213
template_name_list: list[str] | str, using: str | None = ...
13-
) -> Any: ...
14+
) -> Template: ...
1415
def render_to_string(
1516
template_name: list[str] | str,
1617
context: dict[str, Any] | None = ...,

django-stubs/template/utils.pyi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import collections
1+
from collections.abc import Iterator
2+
from pathlib import Path
23
from typing import Any
34

45
from django.core.exceptions import ImproperlyConfigured
@@ -7,10 +8,11 @@ from django.template.backends.base import BaseEngine
78
class InvalidTemplateEngineError(ImproperlyConfigured): ...
89

910
class EngineHandler:
10-
templates: collections.OrderedDict[Any, Any]
1111
def __init__(self, templates: list[dict[str, Any]] = ...) -> None: ...
12+
@property
13+
def templates(self) -> dict[str, dict[str, Any]]: ...
1214
def __getitem__(self, alias: str) -> BaseEngine: ...
13-
def __iter__(self) -> Any: ...
15+
def __iter__(self) -> Iterator[BaseEngine]: ...
1416
def all(self) -> list[BaseEngine]: ...
1517

16-
def get_app_template_dirs(dirname: str) -> tuple[Any, ...]: ...
18+
def get_app_template_dirs(dirname: str) -> tuple[Path, ...]: ...

0 commit comments

Comments
 (0)