fix new mypy 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 9dcb94f · Browse files · 12 files·+15 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
12 files+15 added−17 removed
- tests:+0 added−1 removed
- other:+15 added−16 removed
Provenance
- Commit
cdc4f1d- Tree
e637171- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
9dcb94f
12 files changed+15 added−17 removed
modified:src/jinja2/compiler.py+1 added-1 removed
216 unmodified lines217 self.soft_frame = False218 219 def copy(self) -> "Frame":220 """Create a copy of the current one."""221- rv = t.cast(Frame, object.__new__(self.__class__))221+ rv = object.__new__(self.__class__)222 rv.__dict__.update(self.__dict__)223 rv.symbols = self.symbols.copy()224 return rv225 1732 unmodified linesmodified:src/jinja2/debug.py-2 removed
197 unmodified lines198 ) -> TracebackType:199 tb.tb_next = tb_next200 return tb201 202-202 elif platform.python_implementation() == "PyPy":203 # PyPy might have special support, and won't work with ctypes.204 try:205 import tputil # type: ignore17 unmodified lines223 return op.delegate()224 225 return tputil.make_proxy(controller, obj=tb) # type: ignore226 228-227 else:228 # Use ctypes to assign tb_next at the C level since it's read-only229 # from Python.230 import ctypes27 unmodified linesmodified:src/jinja2/environment.py+6 added-6 removed
936 unmodified lines937 return template938 939 @internalcode940 def _load_template(941- self, name: str, globals: t.Optional[t.Mapping[str, t.Any]]941+ self, name: str, globals: t.Optional[t.MutableMapping[str, t.Any]]942 ) -> "Template":943 if self.loader is None:944 raise TypeError("no loader for this environment specified")945 cache_key = (weakref.ref(self.loader), name)19 unmodified lines965 def get_template(966 self,967 name: t.Union[str, "Template"],968 parent: t.Optional[str] = None,969- globals: t.Optional[t.Mapping[str, t.Any]] = None,969+ globals: t.Optional[t.MutableMapping[str, t.Any]] = None,970 ) -> "Template":971 """Load a template by name with :attr:`loader` and return a972 :class:`Template`. If the template does not exist a973 :exc:`TemplateNotFound` exception is raised.26 unmodified lines1000 def select_template(1001 self,1002 names: t.Iterable[t.Union[str, "Template"]],1003 parent: t.Optional[str] = None,1004- globals: t.Optional[t.Mapping[str, t.Any]] = None,1004+ globals: t.Optional[t.MutableMapping[str, t.Any]] = None,1005 ) -> "Template":1006 """Like :meth:`get_template`, but tries loading multiple names.1007 If none of the names can be loaded a :exc:`TemplatesNotFound`1008 exception is raised.47 unmodified lines1056 template_name_or_list: t.Union[1057 str, "Template", t.List[t.Union[str, "Template"]]1058 ],1059 parent: t.Optional[str] = None,1060- globals: t.Optional[t.Mapping[str, t.Any]] = None,1060+ globals: t.Optional[t.MutableMapping[str, t.Any]] = None,1061 ) -> "Template":1062 """Use :meth:`select_template` if an iterable of template names1063 is given, or :meth:`get_template` if one name is given.1064 7 unmodified lines1072 1073 def from_string(1074 self,1075 source: t.Union[str, nodes.Template],1076- globals: t.Optional[t.Mapping[str, t.Any]] = None,1076+ globals: t.Optional[t.MutableMapping[str, t.Any]] = None,1077 template_class: t.Optional[t.Type["Template"]] = None,1078 ) -> "Template":1079 """Load a template from a source string without using1080 :attr:`loader`.10 unmodified lines1091 cls = template_class or self.template_class1092 return cls.from_code(self, self.compile(source), gs, None)1093 1094 def make_globals(1095- self, d: t.Optional[t.Mapping[str, t.Any]]1095+ self, d: t.Optional[t.MutableMapping[str, t.Any]]1096 ) -> t.MutableMapping[str, t.Any]:1097 """Make the globals map for a template. Any given template1098 globals overlay the environment :attr:`globals`.1099 562 unmodified linesmodified:src/jinja2/ext.py+1 added-1 removed
89 unmodified lines90 self.environment = environment91 92 def bind(self, environment: Environment) -> "Extension":93 """Create a copy of this extension bound to another environment."""94- rv = t.cast(Extension, object.__new__(self.__class__))94+ rv = object.__new__(self.__class__)95 rv.__dict__.update(self.__dict__)96 rv.environment = environment97 return rv98 781 unmodified linesmodified:src/jinja2/idtracking.py+1 added-1 removed
82 unmodified lines83 )84 return rv85 86 def copy(self) -> "Symbols":87- rv = t.cast(Symbols, object.__new__(self.__class__))87+ rv = object.__new__(self.__class__)88 rv.__dict__.update(self.__dict__)89 rv.refs = self.refs.copy()90 rv.loads = self.loads.copy()91 rv.stores = self.stores.copy()227 unmodified linesmodified:src/jinja2/lexer.py+1 added-1 removed
721 unmodified lines722 continue723 724 # tuples support more options725 if isinstance(tokens, tuple):726- groups = m.groups()726+ groups: t.Sequence[str] = m.groups()727 728 if isinstance(tokens, OptionalLStrip):729 # Rule supports lstrip. Match will look like730 # text, block type, whitespace control, type, control, ...139 unmodified linesmodified:src/jinja2/loaders.py+1 added-1 removed
601 unmodified lines602 603 if not isinstance(path, abc.Iterable) or isinstance(path, str):604 path = [path]605 606- mod.__path__ = [os.fspath(p) for p in path] # type: ignore606+ mod.__path__ = [os.fspath(p) for p in path]607 608 sys.modules[package_name] = weakref.proxy(609 mod, lambda x: sys.modules.pop(package_name, None)610 )42 unmodified linesmodified:src/jinja2/parser.py+1 added-1 removed
158 unmodified lines159 """Return a new free identifier as :class:`~jinja2.nodes.InternalName`."""160 self._last_identifier += 1161 rv = object.__new__(nodes.InternalName)162 nodes.Node.__init__(rv, f"fi{self._last_identifier}", lineno=lineno)163- return rv # type: ignore163+ return rv164 165 def parse_statement(self) -> t.Union[nodes.Node, t.List[nodes.Node]]:166 """Parse a single statement."""167 token = self.stream.current873 unmodified linesmodified:src/jinja2/sandbox.py+1 added-1 removed
407 unmodified lines408 409 class SandboxedFormatter(Formatter):410 def __init__(self, env: Environment, **kwargs: t.Any) -> None:411 self._env = env412- super().__init__(**kwargs) # type: ignore412+ super().__init__(**kwargs)413 414 def get_field(415 self, field_name: str, args: t.Sequence[t.Any], kwargs: t.Mapping[str, t.Any]416 ) -> t.Tuple[t.Any, str]:12 unmodified linesmodified:src/jinja2/visitor.py+1 added-1 removed
28 unmodified lines29 """Return the visitor function for this node or `None` if no visitor30 exists for this node. In that case the generic visit function is31 used instead.32 """33- return getattr(self, f"visit_{type(node).__name__}", None) # type: ignore33+ return getattr(self, f"visit_{type(node).__name__}", None)34 35 def visit(self, node: Node, *args: t.Any, **kwargs: t.Any) -> t.Any:36 """Visit a node."""37 f = self.get_visitor(node)55 unmodified linesmodified:tests/test_async.py-1 removed
18 unmodified lines19 def run(coro):20 loop = asyncio.get_event_loop()21 return loop.run_until_complete(coro)22 23-23 else:24 25 def run(coro):26 return asyncio.run(coro)633 unmodified linesmodified:setup.cfg+1 added
85 unmodified lines86 87 [mypy]88 files = src/jinja289 python_version = 3.690+show_error_codes = True91 disallow_subclassing_any = True92 disallow_untyped_calls = True93 disallow_untyped_defs = True94 disallow_incomplete_defs = True15 unmodified lines