Merge pull request #1435 from pallets/update-typing
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Update typing
authored by David Lord · committed by GitHub · parents 21fa00b, 9f34d2a · Browse files · 10 files·+58 added−45 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+58 added−45 removed
- other:+58 added−45 removed
Provenance
- Commit
426c560- Tree
68fb3c0- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
21fa00b- Parent 2
9f34d2a
10 files changed+58 added−45 removed
modified:src/jinja2/__init__.py+31 added-31 removed
1 """Jinja is a template engine written in pure Python. It provides a2 non-XML syntax that supports inline expressions and an optional3 sandboxed environment.4 """5-from .bccache import BytecodeCache6-from .bccache import FileSystemBytecodeCache7-from .bccache import MemcachedBytecodeCache8-from .environment import Environment9-from .environment import Template10-from .exceptions import TemplateAssertionError11-from .exceptions import TemplateError12-from .exceptions import TemplateNotFound13-from .exceptions import TemplateRuntimeError14-from .exceptions import TemplatesNotFound15-from .exceptions import TemplateSyntaxError16-from .exceptions import UndefinedError5+from .bccache import BytecodeCache as BytecodeCache6+from .bccache import FileSystemBytecodeCache as FileSystemBytecodeCache7+from .bccache import MemcachedBytecodeCache as MemcachedBytecodeCache8+from .environment import Environment as Environment9+from .environment import Template as Template10+from .exceptions import TemplateAssertionError as TemplateAssertionError11+from .exceptions import TemplateError as TemplateError12+from .exceptions import TemplateNotFound as TemplateNotFound13+from .exceptions import TemplateRuntimeError as TemplateRuntimeError14+from .exceptions import TemplatesNotFound as TemplatesNotFound15+from .exceptions import TemplateSyntaxError as TemplateSyntaxError16+from .exceptions import UndefinedError as UndefinedError17 from .filters import contextfilter18 from .filters import environmentfilter19 from .filters import evalcontextfilter20-from .loaders import BaseLoader21-from .loaders import ChoiceLoader22-from .loaders import DictLoader23-from .loaders import FileSystemLoader24-from .loaders import FunctionLoader25-from .loaders import ModuleLoader26-from .loaders import PackageLoader27-from .loaders import PrefixLoader28-from .runtime import ChainableUndefined29-from .runtime import DebugUndefined30-from .runtime import make_logging_undefined31-from .runtime import StrictUndefined32-from .runtime import Undefined33-from .utils import clear_caches20+from .loaders import BaseLoader as BaseLoader21+from .loaders import ChoiceLoader as ChoiceLoader22+from .loaders import DictLoader as DictLoader23+from .loaders import FileSystemLoader as FileSystemLoader24+from .loaders import FunctionLoader as FunctionLoader25+from .loaders import ModuleLoader as ModuleLoader26+from .loaders import PackageLoader as PackageLoader27+from .loaders import PrefixLoader as PrefixLoader28+from .runtime import ChainableUndefined as ChainableUndefined29+from .runtime import DebugUndefined as DebugUndefined30+from .runtime import make_logging_undefined as make_logging_undefined31+from .runtime import StrictUndefined as StrictUndefined32+from .runtime import Undefined as Undefined33+from .utils import clear_caches as clear_caches34 from .utils import contextfunction35 from .utils import environmentfunction36 from .utils import escape37 from .utils import evalcontextfunction38-from .utils import is_undefined38+from .utils import is_undefined as is_undefined39 from .utils import Markup40-from .utils import pass_context41-from .utils import pass_environment42-from .utils import pass_eval_context43-from .utils import select_autoescape40+from .utils import pass_context as pass_context41+from .utils import pass_environment as pass_environment42+from .utils import pass_eval_context as pass_eval_context43+from .utils import select_autoescape as select_autoescape44 45 __version__ = "3.0.1.dev0"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+4 added-1 removed
3 unmodified lines4 -------------5 6 Unreleased7 8-- Update MarkupSafe dependency to >= 2.0.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