summaryrefslogtreecommitdiff
path: root/cloudinit/templater.py
diff options
context:
space:
mode:
authorAlberto Contreras <aciba90@gmail.com>2022-05-23 18:30:00 +0200
committerGitHub <noreply@github.com>2022-05-23 11:30:00 -0500
commit53a995e2f852d043d51ad25c1b9afbbe1edafd57 (patch)
treea91be715e11a2cc509a4c953e8f456154ed60589 /cloudinit/templater.py
parent4938c9c1407cdc21daabd70791300c3058a16f71 (diff)
downloadcloud-init-git-53a995e2f852d043d51ad25c1b9afbbe1edafd57.tar.gz
Drop mypy excluded files (#1454)
- Add types to let mypy pass. - Add mypy flags: - detect unused ignores - redundant casts - Drop support of `ConfigParser` in Python 2 - Harden DataSourceLXD.network_config - Convert old-style commented types to proper types.
Diffstat (limited to 'cloudinit/templater.py')
-rw-r--r--cloudinit/templater.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/cloudinit/templater.py b/cloudinit/templater.py
index 298eaf6b..4d712829 100644
--- a/cloudinit/templater.py
+++ b/cloudinit/templater.py
@@ -10,31 +10,38 @@
#
# This file is part of cloud-init. See LICENSE file for license information.
+# noqa: E402
+
import collections
import re
import sys
+from typing import Type
+
+from cloudinit import log as logging
+from cloudinit import type_utils as tu
+from cloudinit import util
+from cloudinit.atomic_helper import write_file
+JUndefined: Type
try:
- from jinja2 import DebugUndefined as JUndefined
+ from jinja2 import DebugUndefined as _DebugUndefined
from jinja2 import Template as JTemplate
JINJA_AVAILABLE = True
+ JUndefined = _DebugUndefined
except (ImportError, AttributeError):
JINJA_AVAILABLE = False
JUndefined = object
-from cloudinit import log as logging
-from cloudinit import type_utils as tu
-from cloudinit import util
-from cloudinit.atomic_helper import write_file
-
LOG = logging.getLogger(__name__)
TYPE_MATCHER = re.compile(r"##\s*template:(.*)", re.I)
BASIC_MATCHER = re.compile(r"\$\{([A-Za-z0-9_.]+)\}|\$([A-Za-z0-9_.]+)")
MISSING_JINJA_PREFIX = "CI_MISSING_JINJA_VAR/"
-class UndefinedJinjaVariable(JUndefined):
+# Mypy, and the PEP 484 ecosystem in general, does not support creating
+# classes with dynamic base types: https://stackoverflow.com/a/59636248
+class UndefinedJinjaVariable(JUndefined): # type: ignore
"""Class used to represent any undefined jinja template variable."""
def __str__(self):