Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary else after return statement (Fix: RET505) #940

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions nornir/core/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
11 changes: 5 additions & 6 deletions nornir/core/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions nornir/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down