From b295785606385fcc787fe8be2a0bb6733e1986e2 Mon Sep 17 00:00:00 2001 From: Jan Graichen Date: Mon, 9 May 2022 18:16:22 +0200 Subject: [PATCH] chore: Fix style issues Use named tuple for Optional call. It does not has logic but only a tiny bit of data. Fix some import ordering style issue too. --- salt_tower/pillar/tower.py | 9 ++++----- salt_tower/renderers/yamlet.py | 5 +++-- 2 files changed, 7 insertions(+), 7 deletions(-) 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):