From 2e84c03632dad96d5cb670922791e95923528210 Mon Sep 17 00:00:00 2001 From: David Smith <39445562+smithdc1@users.noreply.github.com> Date: Wed, 13 Jul 2022 07:48:33 +0100 Subject: [PATCH] Made BaseContext __setitem__ and __getitem__ consistant. (#1040) * Made BaseContext __setitem__ and __getitem__ consistant. * Standardised ContextKeys --- django-stubs/template/context.pyi | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/django-stubs/template/context.pyi b/django-stubs/template/context.pyi index 98e3e84ee..0f5864d40 100644 --- a/django-stubs/template/context.pyi +++ b/django-stubs/template/context.pyi @@ -6,6 +6,7 @@ from django.template.base import Node, Origin, Template from django.template.defaulttags import IfChangedNode from django.template.loader_tags import IncludeNode +_ContextKeys = Union[int, str, Node] _ContextValues = Union[Dict[str, Any], "Context"] _ContextCopy = TypeVar("_ContextCopy", bound="BaseContext") @@ -23,17 +24,17 @@ class BaseContext(Iterable[Any]): def __iter__(self) -> Iterator[Any]: ... def push(self, *args: Any, **kwargs: Any) -> ContextDict: ... def pop(self) -> ContextDict: ... - def __setitem__(self, key: Union[Node, str], value: Any) -> None: ... - def set_upward(self, key: str, value: Union[int, str]) -> None: ... - def __getitem__(self, key: Union[int, str]) -> Any: ... - def __delitem__(self, key: Any) -> None: ... - def __contains__(self, key: str) -> bool: ... - def get(self, key: str, otherwise: Optional[Any] = ...) -> Optional[Any]: ... + def __setitem__(self, key: _ContextKeys, value: Any) -> None: ... + def set_upward(self, key: _ContextKeys, value: Union[int, str]) -> None: ... + def __getitem__(self, key: _ContextKeys) -> Any: ... + def __delitem__(self, key: _ContextKeys) -> None: ... + def __contains__(self, key: _ContextKeys) -> bool: ... + def get(self, key: _ContextKeys, otherwise: Optional[Any] = ...) -> Optional[Any]: ... def setdefault( - self, key: Union[IfChangedNode, str], default: Optional[Union[List[Origin], int]] = ... + self, key: _ContextKeys, default: Optional[Union[List[Origin], int]] = ... ) -> Optional[Union[List[Origin], int]]: ... def new(self, values: Optional[_ContextValues] = ...) -> Context: ... - def flatten(self) -> Dict[str, Optional[Union[Dict[str, Union[Type[Any], str]], int, str]]]: ... + def flatten(self) -> Dict[_ContextKeys, Optional[Union[Dict[_ContextKeys, Union[Type[Any], str]], int, str]]]: ... class Context(BaseContext): dicts: Any