Skip to content
Myr

Merge pull request #1434 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 f1c51b3, 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

10 files+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 a2non-XML syntax that supports inline expressions and an optional3sandboxed environment.4"""5from .bccache import BytecodeCache6from .bccache import FileSystemBytecodeCache7from .bccache import MemcachedBytecodeCache8from .environment import Environment9from .environment import Template10from .exceptions import TemplateAssertionError11from .exceptions import TemplateError12from .exceptions import TemplateNotFound13from .exceptions import TemplateRuntimeError14from .exceptions import TemplatesNotFound15from .exceptions import TemplateSyntaxError16from .exceptions import UndefinedError5from .bccache import BytecodeCache as BytecodeCache6from .bccache import FileSystemBytecodeCache as FileSystemBytecodeCache7from .bccache import MemcachedBytecodeCache as MemcachedBytecodeCache8from .environment import Environment as Environment9from .environment import Template as Template10from .exceptions import TemplateAssertionError as TemplateAssertionError11from .exceptions import TemplateError as TemplateError12from .exceptions import TemplateNotFound as TemplateNotFound13from .exceptions import TemplateRuntimeError as TemplateRuntimeError14from .exceptions import TemplatesNotFound as TemplatesNotFound15from .exceptions import TemplateSyntaxError as TemplateSyntaxError16from .exceptions import UndefinedError as UndefinedError17from .filters import contextfilter18from .filters import environmentfilter19from .filters import evalcontextfilter20from .loaders import BaseLoader21from .loaders import ChoiceLoader22from .loaders import DictLoader23from .loaders import FileSystemLoader24from .loaders import FunctionLoader25from .loaders import ModuleLoader26from .loaders import PackageLoader27from .loaders import PrefixLoader28from .runtime import ChainableUndefined29from .runtime import DebugUndefined30from .runtime import make_logging_undefined31from .runtime import StrictUndefined32from .runtime import Undefined33from .utils import clear_caches20from .loaders import BaseLoader as BaseLoader21from .loaders import ChoiceLoader as ChoiceLoader22from .loaders import DictLoader as DictLoader23from .loaders import FileSystemLoader as FileSystemLoader24from .loaders import FunctionLoader as FunctionLoader25from .loaders import ModuleLoader as ModuleLoader26from .loaders import PackageLoader as PackageLoader27from .loaders import PrefixLoader as PrefixLoader28from .runtime import ChainableUndefined as ChainableUndefined29from .runtime import DebugUndefined as DebugUndefined30from .runtime import make_logging_undefined as make_logging_undefined31from .runtime import StrictUndefined as StrictUndefined32from .runtime import Undefined as Undefined33from .utils import clear_caches as clear_caches34from .utils import contextfunction35from .utils import environmentfunction36from .utils import escape37from .utils import evalcontextfunction38from .utils import is_undefined38from .utils import is_undefined as is_undefined39from .utils import Markup40from .utils import pass_context41from .utils import pass_environment42from .utils import pass_eval_context43from .utils import select_autoescape40from .utils import pass_context as pass_context41from .utils import pass_environment as pass_environment42from .utils import pass_eval_context as pass_eval_context43from .utils import select_autoescape as select_autoescape4445__version__ = "3.1.0.dev0"
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+4 added-1 removed
9 unmodified lines
10-------------1112Unreleased1314- Update MarkupSafe dependency to >= 2.0.14- Update MarkupSafe dependency to >= 2.0. :pr:`1418`15- Mark top-level names as exported so type checking understands16 imports in user projects. :issue:`1426`17- Fix some types that weren't available in Python 3.6.0. :issue:`1433`181920Version 3.0.021-------------
858 unmodified lines