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
Provenance
- Commit
9f34d2a- Tree
68fb3c0- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
db5fb79
9 files changed+24 added−13 removed
modified:src/jinja2/bccache.py+1 added-1 removed
208 unmodified lines209 self.directory = directory210 self.pattern = pattern211 212 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 linesmodified:src/jinja2/compiler.py+2 added-1 removed
21 unmodified lines22 from .utils import concat23 from .visitor import NodeVisitor24 25 if t.TYPE_CHECKING:26+ import typing_extensions as te27 from .environment import Environment28 29 F = t.TypeVar("F", bound=t.Callable[..., t.Any])30 345 unmodified lines376 return self.optimizer is not None377 378 # -- Various compilation helpers379 379- 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)383 384 def temporary_identifier(self) -> str:1570 unmodified linesmodified:src/jinja2/environment.py+1 added-1 removed
913 unmodified lines914 names = [name for name in names if filter_func(name)]915 916 return names917 918- 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_stack734 unmodified linesmodified:src/jinja2/lexer.py+3 added-2 removed
12 unmodified lines13 from .exceptions import TemplateSyntaxError14 from .utils import LRUCache15 16 if t.TYPE_CHECKING:17+ import typing_extensions as te18 from .environment import Environment19 20 # cache for the lexers. Exists in order to be able to have multiple21 # environments with the same lexer237 unmodified lines259 ) -> None:260 self.message = message261 self.error_class = cls262 262- 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)265 266 267 class Token(t.NamedTuple):58 unmodified lines326 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 linesmodified:src/jinja2/nodes.py+2 added-1 removed
10 unmodified lines11 12 from .utils import _PassArg13 14 if t.TYPE_CHECKING:15+ import typing_extensions as te16 from .environment import Environment17 18 _NodeBound = t.TypeVar("_NodeBound", bound="Node")19 1176 unmodified lines1196 body: t.List[Node]1197 1198 1199 # make sure nobody creates custom nodes1199-def _failing_new(*args: t.Any, **kwargs: t.Any) -> t.NoReturn:1200+def _failing_new(*args: t.Any, **kwargs: t.Any) -> "te.NoReturn":1201 raise TypeError("can't create custom node types")1202 1203 1204 NodeType.__new__ = staticmethod(_failing_new) # type: ignore1 unmodified linemodified:src/jinja2/parser.py+6 added-4 removed
74 unmodified lines75 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 lines89 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 lines124 )125 126 self.fail(" ".join(message), lineno)127 128- 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 lines137 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 linesmodified:src/jinja2/runtime.py+4 added-2 removed
892 unmodified lines893 f" attribute {self._undefined_name!r}"894 )895 896 @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 lines986 __slots__ = ()987 988 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: ignore109 unmodified linesmodified:src/jinja2/utils.py+4 added-1 removed
12 unmodified lines13 from urllib.parse import quote_from_bytes14 15 import markupsafe16 17+if t.TYPE_CHECKING:18+ import typing_extensions as te19+20 F = t.TypeVar("F", bound=t.Callable[..., t.Any])21 22 # special singleton representing missing values for the runtime23 missing: t.Any = type("MissingType", (), {"__repr__": lambda x: "missing"})()481 unmodified lines505 506 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()511 512 def _postinit(self) -> None:513 # alias all queue methods for faster lookup341 unmodified linesmodified:CHANGES.rst+1 added
6 unmodified lines7 8 - 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`12 13 14 Version 3.0.015 -------------858 unmodified lines