]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
fix new mypy findings 1558/head
authorDavid Lord <davidism@gmail.com>
Sun, 26 Dec 2021 14:39:10 +0000 (07:39 -0700)
committerDavid Lord <davidism@gmail.com>
Sun, 26 Dec 2021 14:39:10 +0000 (07:39 -0700)
12 files changed:
setup.cfg
src/jinja2/compiler.py
src/jinja2/debug.py
src/jinja2/environment.py
src/jinja2/ext.py
src/jinja2/idtracking.py
src/jinja2/lexer.py
src/jinja2/loaders.py
src/jinja2/parser.py
src/jinja2/sandbox.py
src/jinja2/visitor.py
tests/test_async.py

index f952317e184e4bd1a7e2a1c3eaa934d5cad6a5aa..9dd6c5123de7ad2dc240a3ad567cd6f98030a104 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -87,6 +87,7 @@ per-file-ignores =
 [mypy]
 files = src/jinja2
 python_version = 3.6
+show_error_codes = True
 disallow_subclassing_any = True
 disallow_untyped_calls = True
 disallow_untyped_defs = True
index 52fd5b83e20964930dde5c8d71e149031a48d5bb..c7f94c08bace24e062ea25b6c7b1c04dbfa04801 100644 (file)
@@ -218,7 +218,7 @@ class Frame:
 
     def copy(self) -> "Frame":
         """Create a copy of the current one."""
-        rv = t.cast(Frame, object.__new__(self.__class__))
+        rv = object.__new__(self.__class__)
         rv.__dict__.update(self.__dict__)
         rv.symbols = self.symbols.copy()
         return rv
index 805866bd6f9b04dcde0c36a7e72739f5b3759dd0..a7e555ed5ccefefa76ab3022ed490fc0034b94a1 100644 (file)
@@ -199,7 +199,6 @@ if sys.version_info >= (3, 7):
         tb.tb_next = tb_next
         return tb
 
-
 elif platform.python_implementation() == "PyPy":
     # PyPy might have special support, and won't work with ctypes.
     try:
@@ -225,7 +224,6 @@ elif platform.python_implementation() == "PyPy":
 
             return tputil.make_proxy(controller, obj=tb)  # type: ignore
 
-
 else:
     # Use ctypes to assign tb_next at the C level since it's read-only
     # from Python.
index a231d9cd576177df0c612b49dcd552b7f9c5de56..20df7b20e2ea1458c5d7c65b833bb4efa7041490 100644 (file)
@@ -938,7 +938,7 @@ class Environment:
 
     @internalcode
     def _load_template(
-        self, name: str, globals: t.Optional[t.Mapping[str, t.Any]]
+        self, name: str, globals: t.Optional[t.MutableMapping[str, t.Any]]
     ) -> "Template":
         if self.loader is None:
             raise TypeError("no loader for this environment specified")
@@ -966,7 +966,7 @@ class Environment:
         self,
         name: t.Union[str, "Template"],
         parent: t.Optional[str] = None,
-        globals: t.Optional[t.Mapping[str, t.Any]] = None,
+        globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
     ) -> "Template":
         """Load a template by name with :attr:`loader` and return a
         :class:`Template`. If the template does not exist a
@@ -1001,7 +1001,7 @@ class Environment:
         self,
         names: t.Iterable[t.Union[str, "Template"]],
         parent: t.Optional[str] = None,
-        globals: t.Optional[t.Mapping[str, t.Any]] = None,
+        globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
     ) -> "Template":
         """Like :meth:`get_template`, but tries loading multiple names.
         If none of the names can be loaded a :exc:`TemplatesNotFound`
@@ -1057,7 +1057,7 @@ class Environment:
             str, "Template", t.List[t.Union[str, "Template"]]
         ],
         parent: t.Optional[str] = None,
-        globals: t.Optional[t.Mapping[str, t.Any]] = None,
+        globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
     ) -> "Template":
         """Use :meth:`select_template` if an iterable of template names
         is given, or :meth:`get_template` if one name is given.
@@ -1073,7 +1073,7 @@ class Environment:
     def from_string(
         self,
         source: t.Union[str, nodes.Template],
-        globals: t.Optional[t.Mapping[str, t.Any]] = None,
+        globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
         template_class: t.Optional[t.Type["Template"]] = None,
     ) -> "Template":
         """Load a template from a source string without using
@@ -1092,7 +1092,7 @@ class Environment:
         return cls.from_code(self, self.compile(source), gs, None)
 
     def make_globals(
-        self, d: t.Optional[t.Mapping[str, t.Any]]
+        self, d: t.Optional[t.MutableMapping[str, t.Any]]
     ) -> t.MutableMapping[str, t.Any]:
         """Make the globals map for a template. Any given template
         globals overlay the environment :attr:`globals`.
index 3e982930c4ed496d7bb43058897a8f3268f6caeb..43c04cd23a942d4784e009090b266501c4e19adf 100644 (file)
@@ -91,7 +91,7 @@ class Extension:
 
     def bind(self, environment: Environment) -> "Extension":
         """Create a copy of this extension bound to another environment."""
-        rv = t.cast(Extension, object.__new__(self.__class__))
+        rv = object.__new__(self.__class__)
         rv.__dict__.update(self.__dict__)
         rv.environment = environment
         return rv
index 38c525ee31278c95b93bafd341a0882638746ffd..995ebaa0c8178ddb9e0479e0e9f6d30ed863a785 100644 (file)
@@ -84,7 +84,7 @@ class Symbols:
         return rv
 
     def copy(self) -> "Symbols":
-        rv = t.cast(Symbols, object.__new__(self.__class__))
+        rv = object.__new__(self.__class__)
         rv.__dict__.update(self.__dict__)
         rv.refs = self.refs.copy()
         rv.loads = self.loads.copy()
index c25ab0f6901412ce5ab3f0b5eab793e9e64a987e..b46a7e1d260a4b252453f397a950808ae595248b 100644 (file)
@@ -723,7 +723,7 @@ class Lexer:
 
                 # tuples support more options
                 if isinstance(tokens, tuple):
-                    groups = m.groups()
+                    groups: t.Sequence[str] = m.groups()
 
                     if isinstance(tokens, OptionalLStrip):
                         # Rule supports lstrip. Match will look like
index 4fac3a0966546c387f4018644979780302f4cd4c..d7d9bd04284cfb8747b0f1ca4ee2202fd5c74d98 100644 (file)
@@ -603,7 +603,7 @@ class ModuleLoader(BaseLoader):
         if not isinstance(path, abc.Iterable) or isinstance(path, str):
             path = [path]
 
-        mod.__path__ = [os.fspath(p) for p in path]  # type: ignore
+        mod.__path__ = [os.fspath(p) for p in path]
 
         sys.modules[package_name] = weakref.proxy(
             mod, lambda x: sys.modules.pop(package_name, None)
index 7ad73fcc0f0f3ca5b340447715b27ff404d38a47..44473963142dc8735baeededc33054253c4ef819 100644 (file)
@@ -160,7 +160,7 @@ class Parser:
         self._last_identifier += 1
         rv = object.__new__(nodes.InternalName)
         nodes.Node.__init__(rv, f"fi{self._last_identifier}", lineno=lineno)
-        return rv  # type: ignore
+        return rv
 
     def parse_statement(self) -> t.Union[nodes.Node, t.List[nodes.Node]]:
         """Parse a single statement."""
index 4294884776962e63650df75cb740f76f206f5e0b..06d74148eccea79d1f5a0ca2fb76ecc246f87d62 100644 (file)
@@ -409,7 +409,7 @@ class ImmutableSandboxedEnvironment(SandboxedEnvironment):
 class SandboxedFormatter(Formatter):
     def __init__(self, env: Environment, **kwargs: t.Any) -> None:
         self._env = env
-        super().__init__(**kwargs)  # type: ignore
+        super().__init__(**kwargs)
 
     def get_field(
         self, field_name: str, args: t.Sequence[t.Any], kwargs: t.Mapping[str, t.Any]
index b150e578a8e76ba7b87c5a17ab4de3484ee6053d..71e341e3062431bed6ba3cfc3c717e7e87be873c 100644 (file)
@@ -30,7 +30,7 @@ class NodeVisitor:
         exists for this node.  In that case the generic visit function is
         used instead.
         """
-        return getattr(self, f"visit_{type(node).__name__}", None)  # type: ignore
+        return getattr(self, f"visit_{type(node).__name__}", None)
 
     def visit(self, node: Node, *args: t.Any, **kwargs: t.Any) -> t.Any:
         """Visit a node."""
index 375a7bac33d0ed55ed31daafc0b28880ed93e9a8..ecd9af6bcc2857c6aab57031312550a280063f0d 100644 (file)
@@ -20,7 +20,6 @@ if sys.version_info < (3, 7):
         loop = asyncio.get_event_loop()
         return loop.run_until_complete(coro)
 
-
 else:
 
     def run(coro):