summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2021-02-24 09:47:57 -0800
committerDavid Lord <davidism@gmail.com>2021-02-24 09:49:12 -0800
commitd2cef393550a7461dfe4ed2aeeba6ec83ce91d2a (patch)
tree741f4457d66beb5d6433dc5ed3c3aa057ba1a152
parent9b3c64d5c4d61387ad98d0a75b67c8ba9586647c (diff)
downloadjinja2-d2cef393550a7461dfe4ed2aeeba6ec83ce91d2a.tar.gz
consistent typing config
-rw-r--r--setup.cfg19
-rw-r--r--src/jinja2/compiler.py3
-rw-r--r--src/jinja2/debug.py2
-rw-r--r--src/jinja2/defaults.py6
-rw-r--r--src/jinja2/environment.py6
-rw-r--r--src/jinja2/runtime.py6
-rw-r--r--src/jinja2/utils.py4
-rw-r--r--tox.ini10
8 files changed, 29 insertions, 27 deletions
diff --git a/setup.cfg b/setup.cfg
index 7a5ad7f..bcb2c97 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -84,20 +84,17 @@ per-file-ignores =
[mypy]
files = src/jinja2
-allow_redefinition = True
+python_version = 3.6
disallow_subclassing_any = True
+# disallow_untyped_calls = True
# disallow_untyped_defs = True
+disallow_incomplete_defs = True
+no_implicit_optional = True
+local_partial_types = True
+# no_implicit_reexport = True
strict_equality = True
-strict_optional = False
warn_redundant_casts = True
warn_unused_configs = True
warn_unused_ignores = True
-
-[mypy-_pytest.*]
-ignore_missing_imports = True
-
-[mypy-pytest.*]
-ignore_missing_imports = True
-
-[mypy-requests_unixsocket.*]
-ignore_missing_imports = True
+warn_return_any = True
+warn_unreachable = True
diff --git a/src/jinja2/compiler.py b/src/jinja2/compiler.py
index 3098e3b..df6fa37 100644
--- a/src/jinja2/compiler.py
+++ b/src/jinja2/compiler.py
@@ -1,4 +1,5 @@
"""Compiles nodes from the parser into Python code."""
+import typing as t
from collections import namedtuple
from functools import update_wrapper
from io import StringIO
@@ -1203,7 +1204,7 @@ class CodeGenerator(NodeVisitor):
#: with one. Or if the environment has one, this is called on that
#: function's output for constants.
_default_finalize = str
- _finalize = None
+ _finalize: t.Optional[_FinalizeInfo] = None
def _make_finalize(self):
"""Build the finalize function to be used on constants and at
diff --git a/src/jinja2/debug.py b/src/jinja2/debug.py
index fac5719..8b5cd65 100644
--- a/src/jinja2/debug.py
+++ b/src/jinja2/debug.py
@@ -212,7 +212,7 @@ if sys.version_info >= (3, 7):
elif platform.python_implementation() == "PyPy":
# PyPy might have special support, and won't work with ctypes.
try:
- import tputil
+ import tputil # type: ignore
except ImportError:
# Without tproxy support, use the original traceback.
def tb_set_next(tb, tb_next):
diff --git a/src/jinja2/defaults.py b/src/jinja2/defaults.py
index 6e72b62..a841f61 100644
--- a/src/jinja2/defaults.py
+++ b/src/jinja2/defaults.py
@@ -1,3 +1,5 @@
+import typing as t
+
from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401
from .tests import TESTS as DEFAULT_TESTS # noqa: F401
from .utils import Cycler
@@ -12,8 +14,8 @@ VARIABLE_START_STRING = "{{"
VARIABLE_END_STRING = "}}"
COMMENT_START_STRING = "{#"
COMMENT_END_STRING = "#}"
-LINE_STATEMENT_PREFIX = None
-LINE_COMMENT_PREFIX = None
+LINE_STATEMENT_PREFIX: t.Optional[str] = None
+LINE_COMMENT_PREFIX: t.Optional[str] = None
TRIM_BLOCKS = False
LSTRIP_BLOCKS = False
NEWLINE_SEQUENCE = "\n"
diff --git a/src/jinja2/environment.py b/src/jinja2/environment.py
index 5201bbc..ccc7837 100644
--- a/src/jinja2/environment.py
+++ b/src/jinja2/environment.py
@@ -3,10 +3,10 @@ options.
"""
import os
import sys
+import typing as t
import weakref
from functools import partial
from functools import reduce
-from typing import Any
from markupsafe import Markup
@@ -262,7 +262,7 @@ class Environment:
overlayed = False
#: the environment this environment is linked to if it is an overlay
- linked_to = None
+ linked_to: t.Optional["Environment"] = None
#: shared environments have this set to `True`. A shared environment
#: must not be modified
@@ -276,7 +276,7 @@ class Environment:
#: :class:`~jinja2.runtime.Context` for more information.
context_class = Context
- template_class = Any
+ template_class: t.Type["Template"]
def __init__(
self,
diff --git a/src/jinja2/runtime.py b/src/jinja2/runtime.py
index 166f34f..a05b196 100644
--- a/src/jinja2/runtime.py
+++ b/src/jinja2/runtime.py
@@ -1,5 +1,6 @@
"""The runtime functions and state used by compiled templates."""
import sys
+import typing as t
from collections import abc
from itertools import chain
from types import MethodType
@@ -372,7 +373,7 @@ class LoopContext:
#: Current iteration of the loop, starting at 0.
index0 = -1
- _length = None
+ _length: t.Optional[int] = None
_after = missing
_current = missing
_before = missing
@@ -762,8 +763,7 @@ class Undefined:
return 0
def __iter__(self):
- if 0:
- yield None
+ yield from ()
def __bool__(self):
return False
diff --git a/src/jinja2/utils.py b/src/jinja2/utils.py
index 289d27c..42770b1 100644
--- a/src/jinja2/utils.py
+++ b/src/jinja2/utils.py
@@ -1,11 +1,13 @@
import json
import os
import re
+import typing as t
from collections import abc
from collections import deque
from random import choice
from random import randrange
from threading import Lock
+from types import CodeType
from urllib.parse import quote_from_bytes
from markupsafe import escape
@@ -15,7 +17,7 @@ from markupsafe import Markup
missing = type("MissingType", (), {"__repr__": lambda x: "missing"})()
# internal code
-internal_code = set()
+internal_code: t.MutableSet[CodeType] = set()
concat = "".join
diff --git a/tox.ini b/tox.ini
index a5e83f2..de68730 100644
--- a/tox.ini
+++ b/tox.ini
@@ -2,8 +2,8 @@
envlist =
py{39,38,37,36,py3}
style
- docs
typing
+ docs
skip_missing_interpreters = true
[testenv]
@@ -15,10 +15,10 @@ deps = pre-commit
skip_install = true
commands = pre-commit run --all-files --show-diff-on-failure
-[testenv:docs]
-deps = -r requirements/docs.txt
-commands = sphinx-build -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html
-
[testenv:typing]
deps = -r requirements/typing.txt
commands = mypy
+
+[testenv:docs]
+deps = -r requirements/docs.txt
+commands = sphinx-build -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html