diff options
-rw-r--r-- | CHANGES.rst | 1 | ||||
-rw-r--r-- | src/jinja2/bccache.py | 2 | ||||
-rw-r--r-- | src/jinja2/compiler.py | 3 | ||||
-rw-r--r-- | src/jinja2/environment.py | 2 | ||||
-rw-r--r-- | src/jinja2/lexer.py | 5 | ||||
-rw-r--r-- | src/jinja2/nodes.py | 3 | ||||
-rw-r--r-- | src/jinja2/parser.py | 10 | ||||
-rw-r--r-- | src/jinja2/runtime.py | 6 | ||||
-rw-r--r-- | src/jinja2/utils.py | 5 |
9 files changed, 24 insertions, 13 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index a303e81..bc05ed4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,7 @@ Unreleased - Update MarkupSafe dependency to >= 2.0. :pr:`1418` - Mark top-level names as exported so type checking understands imports in user projects. :issue:`1426` +- Fix some types that weren't available in Python 3.6.0. :issue:`1433` Version 3.0.0 diff --git a/src/jinja2/bccache.py b/src/jinja2/bccache.py index bbe4bee..ee210ef 100644 --- a/src/jinja2/bccache.py +++ b/src/jinja2/bccache.py @@ -210,7 +210,7 @@ class FileSystemBytecodeCache(BytecodeCache): self.pattern = pattern def _get_default_cache_dir(self) -> str: - def _unsafe_dir() -> t.NoReturn: + def _unsafe_dir() -> "te.NoReturn": raise RuntimeError( "Cannot determine safe temp directory. You " "need to explicitly provide one." diff --git a/src/jinja2/compiler.py b/src/jinja2/compiler.py index a8cfe9e..ef4c0a1 100644 --- a/src/jinja2/compiler.py +++ b/src/jinja2/compiler.py @@ -23,6 +23,7 @@ from .utils import concat from .visitor import NodeVisitor if t.TYPE_CHECKING: + import typing_extensions as te from .environment import Environment F = t.TypeVar("F", bound=t.Callable[..., t.Any]) @@ -376,7 +377,7 @@ class CodeGenerator(NodeVisitor): # -- Various compilation helpers - def fail(self, msg: str, lineno: int) -> t.NoReturn: + def fail(self, msg: str, lineno: int) -> "te.NoReturn": """Fail with a :exc:`TemplateAssertionError`.""" raise TemplateAssertionError(msg, lineno, self.name, self.filename) diff --git a/src/jinja2/environment.py b/src/jinja2/environment.py index 833edf7..9c173b2 100644 --- a/src/jinja2/environment.py +++ b/src/jinja2/environment.py @@ -915,7 +915,7 @@ class Environment: return names - def handle_exception(self, source: t.Optional[str] = None) -> t.NoReturn: + def handle_exception(self, source: t.Optional[str] = None) -> "te.NoReturn": """Exception handling helper. This is used internally to either raise rewritten exceptions or return a rendered traceback for the template. """ diff --git a/src/jinja2/lexer.py b/src/jinja2/lexer.py index c151582..9726012 100644 --- a/src/jinja2/lexer.py +++ b/src/jinja2/lexer.py @@ -14,6 +14,7 @@ from .exceptions import TemplateSyntaxError from .utils import LRUCache if t.TYPE_CHECKING: + import typing_extensions as te from .environment import Environment # cache for the lexers. Exists in order to be able to have multiple @@ -259,7 +260,7 @@ class Failure: self.message = message self.error_class = cls - def __call__(self, lineno: int, filename: str) -> t.NoReturn: + def __call__(self, lineno: int, filename: str) -> "te.NoReturn": raise self.error_class(self.message, lineno, filename) @@ -326,7 +327,7 @@ class TokenStream: filename: t.Optional[str], ): self._iter = iter(generator) - self._pushed: t.Deque[Token] = deque() + self._pushed: "te.Deque[Token]" = deque() self.name = name self.filename = filename self.closed = False diff --git a/src/jinja2/nodes.py b/src/jinja2/nodes.py index d867c9b..1feb543 100644 --- a/src/jinja2/nodes.py +++ b/src/jinja2/nodes.py @@ -12,6 +12,7 @@ from markupsafe import Markup from .utils import _PassArg if t.TYPE_CHECKING: + import typing_extensions as te from .environment import Environment _NodeBound = t.TypeVar("_NodeBound", bound="Node") @@ -1196,7 +1197,7 @@ class ScopedEvalContextModifier(EvalContextModifier): # make sure nobody creates custom nodes -def _failing_new(*args: t.Any, **kwargs: t.Any) -> t.NoReturn: +def _failing_new(*args: t.Any, **kwargs: t.Any) -> "te.NoReturn": raise TypeError("can't create custom node types") diff --git a/src/jinja2/parser.py b/src/jinja2/parser.py index 408864c..7ad73fc 100644 --- a/src/jinja2/parser.py +++ b/src/jinja2/parser.py @@ -76,7 +76,7 @@ class Parser: msg: str, lineno: t.Optional[int] = None, exc: t.Type[TemplateSyntaxError] = TemplateSyntaxError, - ) -> t.NoReturn: + ) -> "te.NoReturn": """Convenience method that raises `exc` with the message, passed line number or last line number as well as the current name and filename. @@ -90,7 +90,7 @@ class Parser: name: t.Optional[str], end_token_stack: t.List[t.Tuple[str, ...]], lineno: t.Optional[int], - ) -> t.NoReturn: + ) -> "te.NoReturn": expected: t.Set[str] = set() for exprs in end_token_stack: expected.update(map(describe_token_expr, exprs)) @@ -125,7 +125,9 @@ class Parser: self.fail(" ".join(message), lineno) - def fail_unknown_tag(self, name: str, lineno: t.Optional[int] = None) -> t.NoReturn: + def fail_unknown_tag( + self, name: str, lineno: t.Optional[int] = None + ) -> "te.NoReturn": """Called if the parser encounters an unknown tag. Tries to fail with a human readable error message that could help to identify the problem. @@ -136,7 +138,7 @@ class Parser: self, end_tokens: t.Optional[t.Tuple[str, ...]] = None, lineno: t.Optional[int] = None, - ) -> t.NoReturn: + ) -> "te.NoReturn": """Like fail_unknown_tag but for end of template situations.""" stack = list(self._end_token_stack) if end_tokens is not None: diff --git a/src/jinja2/runtime.py b/src/jinja2/runtime.py index 883c2f7..87bb132 100644 --- a/src/jinja2/runtime.py +++ b/src/jinja2/runtime.py @@ -894,7 +894,9 @@ class Undefined: ) @internalcode - def _fail_with_undefined_error(self, *args: t.Any, **kwargs: t.Any) -> t.NoReturn: + def _fail_with_undefined_error( + self, *args: t.Any, **kwargs: t.Any + ) -> "te.NoReturn": """Raise an :exc:`UndefinedError` when operations are performed on the undefined value. """ @@ -985,7 +987,7 @@ def make_logging_undefined( def _fail_with_undefined_error( # type: ignore self, *args: t.Any, **kwargs: t.Any - ) -> t.NoReturn: + ) -> "te.NoReturn": try: super()._fail_with_undefined_error(*args, **kwargs) except self._undefined_exception as e: diff --git a/src/jinja2/utils.py b/src/jinja2/utils.py index d06c1e4..8531174 100644 --- a/src/jinja2/utils.py +++ b/src/jinja2/utils.py @@ -14,6 +14,9 @@ from urllib.parse import quote_from_bytes import markupsafe +if t.TYPE_CHECKING: + import typing_extensions as te + F = t.TypeVar("F", bound=t.Callable[..., t.Any]) # special singleton representing missing values for the runtime @@ -503,7 +506,7 @@ class LRUCache: def __init__(self, capacity: int) -> None: self.capacity = capacity self._mapping: t.Dict[t.Any, t.Any] = {} - self._queue: t.Deque[t.Any] = deque() + self._queue: "te.Deque[t.Any]" = deque() self._postinit() def _postinit(self) -> None: |