[mypy]
files = src/jinja2
python_version = 3.6
+show_error_codes = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_defs = True
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
tb.tb_next = tb_next
return tb
-
elif platform.python_implementation() == "PyPy":
# PyPy might have special support, and won't work with ctypes.
try:
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.
@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")
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
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`
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.
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
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`.
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
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()
# 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
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)
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."""
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]
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."""
loop = asyncio.get_event_loop()
return loop.run_until_complete(coro)
-
else:
def run(coro):