Skip to content
Myr

fix typing that wasn't available in Python 3.6.0

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 db5fb79 · Browse files · 9 files+24 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

9 files+24 added−13 removed

  • other:+24 added−13 removed

9 files+24 added−13 removed

modified:src/jinja2/bccache.py+1 added-1 removed
208 unmodified lines
209 self.directory = directory210 self.pattern = pattern211212 def _get_default_cache_dir(self) -> str:213 def _unsafe_dir() -> t.NoReturn:213 def _unsafe_dir() -> "te.NoReturn":214 raise RuntimeError(215 "Cannot determine safe temp directory. You "216 "need to explicitly provide one."217 )
147 unmodified lines
modified:src/jinja2/compiler.py+2 added-1 removed
21 unmodified lines
22from .utils import concat23from .visitor import NodeVisitor2425if t.TYPE_CHECKING:26 import typing_extensions as te27 from .environment import Environment2829F = t.TypeVar("F", bound=t.Callable[..., t.Any])30
345 unmodified lines
376 return self.optimizer is not None377378 # -- Various compilation helpers379379 def fail(self, msg: str, lineno: int) -> t.NoReturn:380 def fail(self, msg: str, lineno: int) -> "te.NoReturn":381 """Fail with a :exc:`TemplateAssertionError`."""382 raise TemplateAssertionError(msg, lineno, self.name, self.filename)383384 def temporary_identifier(self) -> str:
1570 unmodified lines
modified:src/jinja2/environment.py+1 added-1 removed
913 unmodified lines
914 names = [name for name in names if filter_func(name)]915916 return names917918 def handle_exception(self, source: t.Optional[str] = None) -> t.NoReturn:918 def handle_exception(self, source: t.Optional[str] = None) -> "te.NoReturn":919 """Exception handling helper. This is used internally to either raise920 rewritten exceptions or return a rendered traceback for the template.921 """922 from .debug import rewrite_traceback_stack
734 unmodified lines
modified:src/jinja2/lexer.py+3 added-2 removed
12 unmodified lines
13from .exceptions import TemplateSyntaxError14from .utils import LRUCache1516if t.TYPE_CHECKING:17 import typing_extensions as te18 from .environment import Environment1920# cache for the lexers. Exists in order to be able to have multiple21# environments with the same lexer
237 unmodified lines
259 ) -> None:260 self.message = message261 self.error_class = cls262262 def __call__(self, lineno: int, filename: str) -> t.NoReturn:263 def __call__(self, lineno: int, filename: str) -> "te.NoReturn":264 raise self.error_class(self.message, lineno, filename)265266267class Token(t.NamedTuple):
58 unmodified lines
326 name: t.Optional[str],327 filename: t.Optional[str],328 ):329 self._iter = iter(generator)329 self._pushed: t.Deque[Token] = deque()330 self._pushed: "te.Deque[Token]" = deque()331 self.name = name332 self.filename = filename333 self.closed = False334 self.current = Token(1, TOKEN_INITIAL, "")
535 unmodified lines
modified:src/jinja2/nodes.py+2 added-1 removed
10 unmodified lines
1112from .utils import _PassArg1314if t.TYPE_CHECKING:15 import typing_extensions as te16 from .environment import Environment1718_NodeBound = t.TypeVar("_NodeBound", bound="Node")19
1176 unmodified lines
1196 body: t.List[Node]119711981199# make sure nobody creates custom nodes1199def _failing_new(*args: t.Any, **kwargs: t.Any) -> t.NoReturn:1200def _failing_new(*args: t.Any, **kwargs: t.Any) -> "te.NoReturn":1201 raise TypeError("can't create custom node types")120212031204NodeType.__new__ = staticmethod(_failing_new) # type: ignore
1 unmodified line
modified:src/jinja2/parser.py+6 added-4 removed
74 unmodified lines
75 self,76 msg: str,77 lineno: t.Optional[int] = None,78 exc: t.Type[TemplateSyntaxError] = TemplateSyntaxError,79 ) -> t.NoReturn:79 ) -> "te.NoReturn":80 """Convenience method that raises `exc` with the message, passed81 line number or last line number as well as the current name and82 filename.83 """
5 unmodified lines
89 self,90 name: t.Optional[str],91 end_token_stack: t.List[t.Tuple[str, ...]],92 lineno: t.Optional[int],93 ) -> t.NoReturn:93 ) -> "te.NoReturn":94 expected: t.Set[str] = set()95 for exprs in end_token_stack:96 expected.update(map(describe_token_expr, exprs))97 if end_token_stack:
26 unmodified lines
124 )125126 self.fail(" ".join(message), lineno)127128 def fail_unknown_tag(self, name: str, lineno: t.Optional[int] = None) -> t.NoReturn:128 def fail_unknown_tag(129 self, name: str, lineno: t.Optional[int] = None130 ) -> "te.NoReturn":131 """Called if the parser encounters an unknown tag. Tries to fail132 with a human readable error message that could help to identify133 the problem.134 """
2 unmodified lines
137 def fail_eof(138 self,139 end_tokens: t.Optional[t.Tuple[str, ...]] = None,140 lineno: t.Optional[int] = None,139 ) -> t.NoReturn:141 ) -> "te.NoReturn":142 """Like fail_unknown_tag but for end of template situations."""143 stack = list(self._end_token_stack)144 if end_tokens is not None:145 stack.append(end_tokens)
895 unmodified lines
modified:src/jinja2/runtime.py+4 added-2 removed
892 unmodified lines
893 f" attribute {self._undefined_name!r}"894 )895896 @internalcode897 def _fail_with_undefined_error(self, *args: t.Any, **kwargs: t.Any) -> t.NoReturn:897 def _fail_with_undefined_error(898 self, *args: t.Any, **kwargs: t.Any899 ) -> "te.NoReturn":900 """Raise an :exc:`UndefinedError` when operations are performed901 on the undefined value.902 """903 raise self._undefined_exception(self._undefined_message)
82 unmodified lines
986 __slots__ = ()987988 def _fail_with_undefined_error( # type: ignore989 self, *args: t.Any, **kwargs: t.Any988 ) -> t.NoReturn:990 ) -> "te.NoReturn":991 try:992 super()._fail_with_undefined_error(*args, **kwargs)993 except self._undefined_exception as e:994 logger.error("Template variable error: %s", e) # type: ignore
109 unmodified lines
modified:src/jinja2/utils.py+4 added-1 removed
12 unmodified lines
13from urllib.parse import quote_from_bytes1415import markupsafe1617if t.TYPE_CHECKING:18 import typing_extensions as te1920F = t.TypeVar("F", bound=t.Callable[..., t.Any])2122# special singleton representing missing values for the runtime23missing: t.Any = type("MissingType", (), {"__repr__": lambda x: "missing"})()
481 unmodified lines
505506 def __init__(self, capacity: int) -> None:507 self.capacity = capacity508 self._mapping: t.Dict[t.Any, t.Any] = {}506 self._queue: t.Deque[t.Any] = deque()509 self._queue: "te.Deque[t.Any]" = deque()510 self._postinit()511512 def _postinit(self) -> None:513 # alias all queue methods for faster lookup
341 unmodified lines
modified:CHANGES.rst+1 added
6 unmodified lines
78- Update MarkupSafe dependency to >= 2.0. :pr:`1418`9- Mark top-level names as exported so type checking understands10 imports in user projects. :issue:`1426`11- Fix some types that weren't available in Python 3.6.0. :issue:`1433`121314Version 3.0.015-------------
858 unmodified lines