diff --git a/salt_tower/pillar/tower.py b/salt_tower/pillar/tower.py index 9cd9bb9..1a26923 100644 --- a/salt_tower/pillar/tower.py +++ b/salt_tower/pillar/tower.py @@ -11,7 +11,7 @@ import os import string from glob import glob -from typing import TYPE_CHECKING, Any, Dict +from typing import TYPE_CHECKING, Any, Dict, NamedTuple import salt.loader import salt.minion @@ -68,16 +68,15 @@ def ext_pillar(minion_id, pillar, *args, **_kwargs): return dict(tower) -class Optional: - def __init__(self, pattern): - self.pattern = pattern +class Optional(NamedTuple): + pattern: str def _yamlet_construct_optional(_loader, node): if isinstance(node, ScalarNode): return Optional(node.value) - raise ConstructorError( + raise ConstructorError( #pylint: disable=duplicate-code None, None, f"expected a scalar node, but found {node.id}", diff --git a/salt_tower/renderers/yamlet.py b/salt_tower/renderers/yamlet.py index c222537..fa163b6 100644 --- a/salt_tower/renderers/yamlet.py +++ b/salt_tower/renderers/yamlet.py @@ -21,14 +21,15 @@ import salt.template from salt.utils.odict import OrderedDict from salt.utils.yamlloader import SaltYamlSafeLoader, load -from yaml.constructor import ConstructorError -from yaml.nodes import MappingNode, ScalarNode try: from salt.utils.files import fopen except ImportError: from salt.utils import fopen +from yaml.constructor import ConstructorError +from yaml.nodes import MappingNode, ScalarNode + class YamletLoader(SaltYamlSafeLoader): # pylint: disable=too-many-ancestors def __init__(self, stream, renderers, context=None, tmplpath=None, **kwargs):