Skip to content

Commit

Permalink
Improve django.template (#210)
Browse files Browse the repository at this point in the history
- `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`.
  • Loading branch information
noelleleigh authored Nov 10, 2023
1 parent d44899f commit cdf62dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions django-stubs/template/loader.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from typing import Any

from django.http.request import HttpRequest
from django.template.base import Template
from django.template.exceptions import ( # noqa: F401
TemplateDoesNotExist as TemplateDoesNotExist,
)

from . import engines as engines # noqa: F401

def get_template(template_name: str, using: str | None = ...) -> Any: ...
def get_template(template_name: str, using: str | None = ...) -> Template: ...
def select_template(
template_name_list: list[str] | str, using: str | None = ...
) -> Any: ...
) -> Template: ...
def render_to_string(
template_name: list[str] | str,
context: dict[str, Any] | None = ...,
Expand Down
10 changes: 6 additions & 4 deletions django-stubs/template/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import collections
from collections.abc import Iterator
from pathlib import Path
from typing import Any

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

class EngineHandler:
templates: collections.OrderedDict[Any, Any]
def __init__(self, templates: list[dict[str, Any]] = ...) -> None: ...
@property
def templates(self) -> dict[str, dict[str, Any]]: ...
def __getitem__(self, alias: str) -> BaseEngine: ...
def __iter__(self) -> Any: ...
def __iter__(self) -> Iterator[BaseEngine]: ...
def all(self) -> list[BaseEngine]: ...

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

0 comments on commit cdf62dd

Please sign in to comment.