From: David Lord Date: Fri, 23 Aug 2024 23:49:44 +0000 (-0700) Subject: apply ruff fixes X-Git-Tag: 3.1.5~38 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3adf44dde21117f784aef4a99d8083166b9f80ef;p=thirdparty%2Fjinja.git apply ruff fixes --- diff --git a/pyproject.toml b/pyproject.toml index 5de076b1..a7cfa7f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,7 +91,6 @@ select = [ "UP", # pyupgrade "W", # pycodestyle warning ] -ignore-init-module-imports = true [tool.ruff.lint.isort] force-single-line = true diff --git a/src/jinja2/async_utils.py b/src/jinja2/async_utils.py index b0d277de..f0c14020 100644 --- a/src/jinja2/async_utils.py +++ b/src/jinja2/async_utils.py @@ -67,7 +67,7 @@ async def auto_await(value: t.Union[t.Awaitable["V"], "V"]) -> "V": if inspect.isawaitable(value): return await t.cast("t.Awaitable[V]", value) - return t.cast("V", value) + return value class _IteratorToAsyncIterator(t.Generic[V]): diff --git a/src/jinja2/debug.py b/src/jinja2/debug.py index 7ed7e929..eeeeee78 100644 --- a/src/jinja2/debug.py +++ b/src/jinja2/debug.py @@ -152,7 +152,7 @@ def get_template_locals(real_locals: t.Mapping[str, t.Any]) -> t.Dict[str, t.Any available at that point in the template. """ # Start with the current template context. - ctx: "t.Optional[Context]" = real_locals.get("context") + ctx: t.Optional[Context] = real_locals.get("context") if ctx is not None: data: t.Dict[str, t.Any] = ctx.get_all().copy() diff --git a/src/jinja2/environment.py b/src/jinja2/environment.py index 57a7f896..f062e407 100644 --- a/src/jinja2/environment.py +++ b/src/jinja2/environment.py @@ -706,7 +706,7 @@ class Environment: return compile(source, filename, "exec") @typing.overload - def compile( # type: ignore + def compile( self, source: t.Union[str, nodes.Template], name: t.Optional[str] = None, @@ -1248,7 +1248,7 @@ class Template: namespace: t.MutableMapping[str, t.Any], globals: t.MutableMapping[str, t.Any], ) -> "Template": - t: "Template" = object.__new__(cls) + t: Template = object.__new__(cls) t.environment = environment t.globals = globals t.name = namespace["name"] diff --git a/src/jinja2/filters.py b/src/jinja2/filters.py index acd11976..14208770 100644 --- a/src/jinja2/filters.py +++ b/src/jinja2/filters.py @@ -1116,7 +1116,7 @@ def do_batch( {%- endfor %} """ - tmp: "t.List[V]" = [] + tmp: t.List[V] = [] for item in value: if len(tmp) == linecount: diff --git a/src/jinja2/idtracking.py b/src/jinja2/idtracking.py index 995ebaa0..d6cb635b 100644 --- a/src/jinja2/idtracking.py +++ b/src/jinja2/idtracking.py @@ -146,7 +146,7 @@ class Symbols: def dump_stores(self) -> t.Dict[str, str]: rv: t.Dict[str, str] = {} - node: t.Optional["Symbols"] = self + node: t.Optional[Symbols] = self while node is not None: for name in sorted(node.stores): @@ -159,7 +159,7 @@ class Symbols: def dump_param_targets(self) -> t.Set[str]: rv = set() - node: t.Optional["Symbols"] = self + node: t.Optional[Symbols] = self while node is not None: for target, (instr, _) in self.loads.items(): diff --git a/src/jinja2/lexer.py b/src/jinja2/lexer.py index 62b0471a..6dc94b67 100644 --- a/src/jinja2/lexer.py +++ b/src/jinja2/lexer.py @@ -329,7 +329,7 @@ class TokenStream: filename: t.Optional[str], ): self._iter = iter(generator) - self._pushed: "te.Deque[Token]" = deque() + self._pushed: te.Deque[Token] = deque() self.name = name self.filename = filename self.closed = False diff --git a/src/jinja2/parser.py b/src/jinja2/parser.py index 0ec997fb..22f3f81f 100644 --- a/src/jinja2/parser.py +++ b/src/jinja2/parser.py @@ -64,7 +64,7 @@ class Parser: self.filename = filename self.closed = False self.extensions: t.Dict[ - str, t.Callable[["Parser"], t.Union[nodes.Node, t.List[nodes.Node]]] + str, t.Callable[[Parser], t.Union[nodes.Node, t.List[nodes.Node]]] ] = {} for extension in environment.iter_extensions(): for tag in extension.tags: diff --git a/src/jinja2/runtime.py b/src/jinja2/runtime.py index 4325c8de..53582ae8 100644 --- a/src/jinja2/runtime.py +++ b/src/jinja2/runtime.py @@ -172,7 +172,7 @@ class Context: ): self.parent = parent self.vars: t.Dict[str, t.Any] = {} - self.environment: "Environment" = environment + self.environment: Environment = environment self.eval_ctx = EvalContext(self.environment, name) self.exported_vars: t.Set[str] = set() self.name = name diff --git a/src/jinja2/sandbox.py b/src/jinja2/sandbox.py index 0b4fc12d..ce276156 100644 --- a/src/jinja2/sandbox.py +++ b/src/jinja2/sandbox.py @@ -5,11 +5,11 @@ Useful when the template itself comes from an untrusted source. import operator import types import typing as t +from _string import formatter_field_name_split # type: ignore from collections import abc from collections import deque from string import Formatter -from _string import formatter_field_name_split # type: ignore from markupsafe import EscapeFormatter from markupsafe import Markup diff --git a/src/jinja2/utils.py b/src/jinja2/utils.py index 7fb76935..5c1ff5d7 100644 --- a/src/jinja2/utils.py +++ b/src/jinja2/utils.py @@ -428,7 +428,7 @@ class LRUCache: def __init__(self, capacity: int) -> None: self.capacity = capacity self._mapping: t.Dict[t.Any, t.Any] = {} - self._queue: "te.Deque[t.Any]" = deque() + self._queue: te.Deque[t.Any] = deque() self._postinit() def _postinit(self) -> None: