fix mypy strict findings
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 614b045 · Browse files · 11 files·+61 added−38 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+61 added−38 removed
- other:+61 added−38 removed
Provenance
- Commit
8ed8e1d- Tree
842087b- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
614b045
11 files changed+61 added−38 removed
modified:src/jinja2/async_utils.py+1 added-1 removed
45 unmodified lines46 47 if need_eval_context:48 wrapper = pass_eval_context(wrapper)49 50- wrapper.jinja_async_variant = True50+ wrapper.jinja_async_variant = True # type: ignore[attr-defined]51 return wrapper52 53 return decorator54 30 unmodified linesmodified:src/jinja2/environment.py+7 added-5 removed
77 unmodified lines78 79 80 def create_cache(81 size: int,82-) -> t.Optional[t.MutableMapping[t.Tuple[weakref.ref, str], "Template"]]:82+) -> t.Optional[t.MutableMapping[t.Tuple["weakref.ref[BaseLoader]", str], "Template"]]:83 """Return the cache class for the given size."""84 if size == 0:85 return None86 3 unmodified lines90 return LRUCache(size) # type: ignore91 92 93 def copy_cache(94- cache: t.Optional[t.MutableMapping],95-) -> t.Optional[t.MutableMapping[t.Tuple[weakref.ref, str], "Template"]]:94+ cache: t.Optional[95+ t.MutableMapping[t.Tuple["weakref.ref[BaseLoader]", str], "Template"]96+ ],97+) -> t.Optional[t.MutableMapping[t.Tuple["weakref.ref[BaseLoader]", str], "Template"]]:98 """Create an empty copy of the given cache."""99 if cache is None:100 return None101 713 unmodified lines815 return TemplateExpression(template, undefined_to_none)816 817 def compile_templates(818 self,817- target: t.Union[str, os.PathLike],819+ target: t.Union[str, "os.PathLike[str]"],820 extensions: t.Optional[t.Collection[str]] = None,821 filter_func: t.Optional[t.Callable[[str], bool]] = None,822 zip: t.Optional[str] = "deflated",823 log_function: t.Optional[t.Callable[[str], None]] = None,765 unmodified lines1589 self.disable_buffering()1590 1591 def dump(1592 self,1591- fp: t.Union[str, t.IO],1593+ fp: t.Union[str, t.IO[t.Any]],1594 encoding: t.Optional[str] = None,1595 errors: t.Optional[str] = "strict",1596 ) -> None:1597 """Dump the complete stream into a file or file-like object.72 unmodified linesmodified:src/jinja2/filters.py+23 added-19 removed
536 unmodified lines537 538 @pass_eval_context539 def sync_do_join(540 eval_ctx: "EvalContext",541- value: t.Iterable,541+ value: t.Iterable[t.Any],542 d: str = "",543 attribute: t.Optional[t.Union[str, int]] = None,544 ) -> str:545 """Return a string which is the concatenation of the strings in the49 unmodified lines595 596 @async_variant(sync_do_join) # type: ignore597 async def do_join(598 eval_ctx: "EvalContext",599- value: t.Union[t.AsyncIterable, t.Iterable],599+ value: t.Union[t.AsyncIterable[t.Any], t.Iterable[t.Any]],600 d: str = "",601 attribute: t.Optional[t.Union[str, int]] = None,602 ) -> str:603 return sync_do_join(eval_ctx, await auto_to_list(value), d, attribute)541 unmodified lines1145 1146 1147 class _GroupTuple(t.NamedTuple):1148 grouper: t.Any1149- list: t.List1149+ list: t.List[t.Any]1150 1151 # Use the regular tuple repr to hide this subclass if users print1152 # out the value during debugging.1153 def __repr__(self) -> str:247 unmodified lines1401 1402 1403 @typing.overload1404 def sync_do_map(1405- context: "Context", value: t.Iterable, name: str, *args: t.Any, **kwargs: t.Any1406-) -> t.Iterable:1405+ context: "Context",1406+ value: t.Iterable[t.Any],1407+ name: str,1408+ *args: t.Any,1409+ **kwargs: t.Any,1410+) -> t.Iterable[t.Any]:1411 ...1412 1413 1414 @typing.overload1415 def sync_do_map(1416 context: "Context",1413- value: t.Iterable,1417+ value: t.Iterable[t.Any],1418 *,1419 attribute: str = ...,1420 default: t.Optional[t.Any] = None,1417-) -> t.Iterable:1421+) -> t.Iterable[t.Any]:1422 ...1423 1424 1425 @pass_context1426 def sync_do_map(1423- context: "Context", value: t.Iterable, *args: t.Any, **kwargs: t.Any1424-) -> t.Iterable:1427+ context: "Context", value: t.Iterable[t.Any], *args: t.Any, **kwargs: t.Any1428+) -> t.Iterable[t.Any]:1429 """Applies a filter on a sequence of objects or looks up an attribute.1430 This is useful when dealing with lists of objects but you are really1431 only interested in a certain value of it.1432 41 unmodified lines1474 1475 @typing.overload1476 def do_map(1477 context: "Context",1474- value: t.Union[t.AsyncIterable, t.Iterable],1478+ value: t.Union[t.AsyncIterable[t.Any], t.Iterable[t.Any]],1479 name: str,1480 *args: t.Any,1481 **kwargs: t.Any,1478-) -> t.Iterable:1482+) -> t.Iterable[t.Any]:1483 ...1484 1485 1486 @typing.overload1487 def do_map(1488 context: "Context",1485- value: t.Union[t.AsyncIterable, t.Iterable],1489+ value: t.Union[t.AsyncIterable[t.Any], t.Iterable[t.Any]],1490 *,1491 attribute: str = ...,1492 default: t.Optional[t.Any] = None,1489-) -> t.Iterable:1493+) -> t.Iterable[t.Any]:1494 ...1495 1496 1497 @async_variant(sync_do_map) # type: ignore1498 async def do_map(1499 context: "Context",1496- value: t.Union[t.AsyncIterable, t.Iterable],1500+ value: t.Union[t.AsyncIterable[t.Any], t.Iterable[t.Any]],1501 *args: t.Any,1502 **kwargs: t.Any,1499-) -> t.AsyncIterable:1503+) -> t.AsyncIterable[t.Any]:1504 if value:1505 func = prepare_map(context, args, kwargs)1506 1507 async for item in auto_aiter(value):184 unmodified lines1692 return htmlsafe_json_dumps(value, dumps=dumps, **kwargs)1693 1694 1695 def prepare_map(1692- context: "Context", args: t.Tuple, kwargs: t.Dict[str, t.Any]1696+ context: "Context", args: t.Tuple[t.Any, ...], kwargs: t.Dict[str, t.Any]1697 ) -> t.Callable[[t.Any], t.Any]:1698 if not args and "attribute" in kwargs:1699 attribute = kwargs.pop("attribute")1700 default = kwargs.pop("default", None)20 unmodified lines1721 1722 1723 def prepare_select_or_reject(1724 context: "Context",1721- args: t.Tuple,1725+ args: t.Tuple[t.Any, ...],1726 kwargs: t.Dict[str, t.Any],1727 modfunc: t.Callable[[t.Any], t.Any],1728 lookup_attr: bool,1729 ) -> t.Callable[[t.Any], t.Any]:26 unmodified lines1756 1757 def select_or_reject(1758 context: "Context",1759 value: "t.Iterable[V]",1756- args: t.Tuple,1760+ args: t.Tuple[t.Any, ...],1761 kwargs: t.Dict[str, t.Any],1762 modfunc: t.Callable[[t.Any], t.Any],1763 lookup_attr: bool,1764 ) -> "t.Iterator[V]":7 unmodified lines1772 1773 async def async_select_or_reject(1774 context: "Context",1775 value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",1772- args: t.Tuple,1776+ args: t.Tuple[t.Any, ...],1777 kwargs: t.Dict[str, t.Any],1778 modfunc: t.Callable[[t.Any], t.Any],1779 lookup_attr: bool,1780 ) -> "t.AsyncIterator[V]":64 unmodified linesmodified:src/jinja2/lexer.py+1 added-1 removed
445 unmodified lines446 447 return lexer448 449 450-class OptionalLStrip(tuple):450+class OptionalLStrip(tuple): # type: ignore[type-arg]451 """A special tuple for marking a point in the state that can have452 lstrip applied.453 """454 412 unmodified linesmodified:src/jinja2/loaders.py+7 added-2 removed
175 unmodified lines176 """177 178 def __init__(179 self,180- searchpath: t.Union[str, os.PathLike, t.Sequence[t.Union[str, os.PathLike]]],180+ searchpath: t.Union[181+ str, "os.PathLike[str]", t.Sequence[t.Union[str, "os.PathLike[str]"]]182+ ],183 encoding: str = "utf-8",184 followlinks: bool = False,185 ) -> None:186 if not isinstance(searchpath, abc.Iterable) or isinstance(searchpath, str):412 unmodified lines599 600 has_source_access = False601 602 def __init__(601- self, path: t.Union[str, os.PathLike, t.Sequence[t.Union[str, os.PathLike]]]603+ self,604+ path: t.Union[605+ str, "os.PathLike[str]", t.Sequence[t.Union[str, "os.PathLike[str]"]]606+ ],607 ) -> None:608 package_name = f"_jinja2_module_templates_{id(self):x}"609 610 # create a fake module that looks for the templates in the53 unmodified linesmodified:src/jinja2/nodes.py+1 added-1 removed
54 unmodified lines55 automatically forwarded to the child."""56 57 def __new__(mcs, name, bases, d): # type: ignore58 for attr in "fields", "attributes":59- storage = []59+ storage: t.List[t.Any] = []60 storage.extend(getattr(bases[0] if bases else object, attr, ()))61 storage.extend(d.get(attr, ()))62 assert len(bases) <= 1, "multiple inheritance not allowed"63 assert len(storage) == len(set(storage)), "layout conflict"1141 unmodified linesmodified:src/jinja2/parser.py+9 added-2 removed
857 unmodified lines858 args.append(None)859 860 return nodes.Slice(lineno=lineno, *args)861 862- def parse_call_args(self) -> t.Tuple:862+ def parse_call_args(863+ self,864+ ) -> t.Tuple[865+ t.List[nodes.Expr],866+ t.List[nodes.Keyword],867+ t.Union[nodes.Expr, None],868+ t.Union[nodes.Expr, None],869+ ]:870 token = self.stream.expect("lparen")871 args = []872 kwargs = []873 dyn_args = None82 unmodified lines956 while self.stream.current.type == "dot":957 next(self.stream)958 name += "." + self.stream.expect("name").value959 dyn_args = dyn_kwargs = None953- kwargs = []960+ kwargs: t.List[nodes.Keyword] = []961 if self.stream.current.type == "lparen":962 args, kwargs, dyn_args, dyn_kwargs = self.parse_call_args()963 elif self.stream.current.type in {964 "name",75 unmodified linesmodified:src/jinja2/runtime.py+4 added-1 removed
257 unmodified lines258 return dict(self.parent, **self.vars)259 260 @internalcode261 def call(262- __self, __obj: t.Callable, *args: t.Any, **kwargs: t.Any # noqa: B902262+ __self, # noqa: B902263+ __obj: t.Callable[..., t.Any],264+ *args: t.Any,265+ **kwargs: t.Any,266 ) -> t.Union[t.Any, "Undefined"]:267 """Call the callable with the arguments and keyword arguments268 provided but inject the active context or environment as first269 argument if the callable has :func:`pass_context` or787 unmodified linesmodified:src/jinja2/sandbox.py+3 added-3 removed
35 unmodified lines36 37 #: unsafe attributes on async generators38 UNSAFE_ASYNC_GENERATOR_ATTRIBUTES = {"ag_code", "ag_frame"}39 40-_mutable_spec: t.Tuple[t.Tuple[t.Type, t.FrozenSet[str]], ...] = (40+_mutable_spec: t.Tuple[t.Tuple[t.Type[t.Any], t.FrozenSet[str]], ...] = (41 (42 abc.MutableSet,43 frozenset(44 [34 unmodified lines79 ),80 )81 82 83-def inspect_format_method(callable: t.Callable) -> t.Optional[str]:83+def inspect_format_method(callable: t.Callable[..., t.Any]) -> t.Optional[str]:84 if not isinstance(85 callable, (types.MethodType, types.BuiltinMethodType)86 ) or callable.__name__ not in ("format", "format_map"):87 return None261 unmodified lines349 self,350 s: str,351 args: t.Tuple[t.Any, ...],352 kwargs: t.Dict[str, t.Any],353- format_func: t.Optional[t.Callable] = None,353+ format_func: t.Optional[t.Callable[..., t.Any]] = None,354 ) -> str:355 """If a format call is detected, then this is routed through this356 method so that our safety sandbox can be used for it.357 """71 unmodified linesmodified:src/jinja2/tests.py+1 added-1 removed
202 unmodified lines203 """Check if the value is escaped."""204 return hasattr(value, "__html__")205 206 207-def test_in(value: t.Any, seq: t.Container) -> bool:207+def test_in(value: t.Any, seq: t.Container[t.Any]) -> bool:208 """Check if value is in seq.209 210 .. versionadded:: 2.10211 """44 unmodified linesmodified:src/jinja2/utils.py+4 added-2 removed
150 unmodified lines151 if not silent:152 raise153 154 155-def open_if_exists(filename: str, mode: str = "rb") -> t.Optional[t.IO]:155+def open_if_exists(filename: str, mode: str = "rb") -> t.Optional[t.IO[t.Any]]:156 """Returns a file descriptor for the filename if that file exists,157 otherwise ``None``.158 """159 if not os.path.isfile(filename):289 unmodified lines449 def __setstate__(self, d: t.Mapping[str, t.Any]) -> None:450 self.__dict__.update(d)451 self._postinit()452 453- def __getnewargs__(self) -> t.Tuple:453+ def __getnewargs__(454+ self,455+ ) -> t.Tuple[int,]:456 return (self.capacity,)457 458 def copy(self) -> "LRUCache":459 """Return a shallow copy of the instance."""298 unmodified lines