]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
consistent typing config
authorDavid Lord <davidism@gmail.com>
Wed, 24 Feb 2021 17:47:57 +0000 (09:47 -0800)
committerDavid Lord <davidism@gmail.com>
Wed, 24 Feb 2021 17:49:12 +0000 (09:49 -0800)
setup.cfg
src/jinja2/compiler.py
src/jinja2/debug.py
src/jinja2/defaults.py
src/jinja2/environment.py
src/jinja2/runtime.py
src/jinja2/utils.py
tox.ini

index 7a5ad7f6f2474b85042d968a719c90eea9f450cc..bcb2c97770d571128d5e166aca332a779d0ce814 100644 (file)
--- 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
index 3098e3b1c6d6c5f49bac18247e048e1845248dcb..df6fa372e60182cbadabd437a538f3c3997d102e 100644 (file)
@@ -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
index fac5719985cd8cb6b9c3b22bc6e07c4c783d3135..8b5cd657a86a811e37310f38f98215ee5ede61c0 100644 (file)
@@ -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):
index 6e72b624599f96f607c78959fd083da46a8a4f8d..a841f616500c92c57b4de826d51376793736abf6 100644 (file)
@@ -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"
index 5201bbc1fa6da3cbf938fb3a0afe0ca28e8b7873..ccc7837da7550c387125a6e89a21d27fa7873871 100644 (file)
@@ -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,
index 166f34f04b8827facb753c90f982355f1196edb4..a05b196118bc355c10f1cfff245a958c1089e968 100644 (file)
@@ -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
index 289d27c6df58eda457c99bcf6604d8609a949a8c..42770b1939a2071905af1d612d0e629570ce8a5d 100644 (file)
@@ -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 a5e83f2ee253286837834502d64207d63afe8016..de68730f28d9d0633ae9f4cb4a89025130abaa7b 100644 (file)
--- 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