diff --git a/nornir/core/filter.py b/nornir/core/filter.py index 91665f0b..a4300cde 100644 --- a/nornir/core/filter.py +++ b/nornir/core/filter.py @@ -80,28 +80,27 @@ def _verify_rules(data: Any, rule: List[str], value: Any) -> bool: if hasattr(data, operator): return getattr(data, operator)(value) is True - elif hasattr(data, rule[0]): + if hasattr(data, rule[0]): if callable(getattr(data, rule[0])): return bool(getattr(data, rule[0])(value)) + return bool(getattr(data, rule[0]) == value) - else: - return bool(getattr(data, rule[0]) == value) - - elif rule == ["in"]: + if rule == ["in"]: return bool(data in value) - elif rule == ["any"]: + + if rule == ["any"]: if isinstance(data, list): return any([x in data for x in value]) - else: - return any([x == data for x in value]) - elif rule == ["all"]: + return any([x == data for x in value]) + + if rule == ["all"]: if isinstance(data, list): return all([x in data for x in value]) - else: - # it doesn't make sense to check a single value meets more than one case - return False - else: - return bool(data.get(rule[0]) == value) + + # it doesn't make sense to check a single value meets more than one case + return False + + return bool(data.get(rule[0]) == value) else: raise Exception("I don't know how I got here:\n{}\n{}\n{}".format(data, rule, value)) diff --git a/nornir/core/inventory.py b/nornir/core/inventory.py index 524e7b35..f47b28fa 100644 --- a/nornir/core/inventory.py +++ b/nornir/core/inventory.py @@ -96,8 +96,8 @@ class ParentGroups(List["Group"]): def __contains__(self, value: object) -> bool: if isinstance(value, str): return any([value == g.name for g in self]) - else: - return any([value == g for g in self]) + + return any([value == g for g in self]) def add(self, group: "Group") -> None: """ @@ -318,8 +318,7 @@ def has_parent_group(self, group: Union[str, "Group"]) -> bool: if isinstance(group, str): return self._has_parent_group_by_name(group) - else: - return self._has_parent_group_by_object(group) + return self._has_parent_group_by_object(group) def _has_parent_group_by_name(self, group: str) -> bool: for g in self.groups: @@ -362,8 +361,8 @@ def __getattribute__(self, name: str) -> Any: return r return object.__getattribute__(self.defaults, name) - else: - return v + + return v def __bool__(self) -> bool: return bool(self.name) diff --git a/nornir/core/task.py b/nornir/core/task.py index 2000881d..27e61fd6 100644 --- a/nornir/core/task.py +++ b/nornir/core/task.py @@ -237,8 +237,7 @@ def __str__(self) -> str: if self.exception: return str(self.exception) - else: - return str(self.result) + return str(self.result) class MultiResult(List[Result]): diff --git a/pyproject.toml b/pyproject.toml index 52b3cdb9..34e8f668 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -156,7 +156,6 @@ ignore = [ "PTH120", # `os.path.dirname()` should be replaced by `Path.parent` "PTH123", # `open()` should be replaced by `Path.open()` "PYI036", # The first argument in `__exit__` should be annotated with `object` or `type[BaseException] | None` - "RET505", # Unnecessary `else` after `return` statement "RET504", # Unnecessary assignment before `return` statement "RSE102", # Unnecessary parentheses on raised exception "RUF001", # String contains ambiguous `–` (EN DASH). Did you mean `-` (HYPHEN-MINUS)?