Skip to content

Commit

Permalink
Remove unnecessary list comprehension
Browse files Browse the repository at this point in the history
  • Loading branch information
ogenstad committed Jul 1, 2024
1 parent a304100 commit aab274a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions nornir/core/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def _verify_rules(data: Any, rule: List[str], value: Any) -> bool:

if rule == ["any"]:
if isinstance(data, list):
return any([x in data for x in value])
return any([x == data for x in value])
return any(x in data for x in value)
return any(x == data for x in value)

if rule == ["all"]:
if isinstance(data, list):
return all([x in data for x in value])
return all(x in data for x in value)

# it doesn't make sense to check a single value meets more than one case
return False
Expand Down
4 changes: 2 additions & 2 deletions nornir/core/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def dict(self) -> Dict[str, Any]:
class ParentGroups(List["Group"]):
def __contains__(self, value: object) -> bool:
if isinstance(value, str):
return any([value == g.name for g in self])
return any(value == g.name for g in self)

return any([value == g for g in self])
return any(value == g for g in self)

def add(self, group: "Group") -> None:
"""
Expand Down
6 changes: 3 additions & 3 deletions nornir/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ def __repr__(self) -> str:
@property
def failed(self) -> bool:
"""If ``True`` at least a task failed."""
return any([h.failed for h in self])
return any(h.failed for h in self)

@property
def changed(self) -> bool:
"""If ``True`` at least a task changed the system."""
return any([h.changed for h in self])
return any(h.changed for h in self)

def raise_on_error(self) -> None:
"""
Expand All @@ -290,7 +290,7 @@ def __repr__(self) -> str:
@property
def failed(self) -> bool:
"""If ``True`` at least a host failed."""
return any([h.failed for h in self.values()])
return any(h.failed for h in self.values())

@property
def failed_hosts(self) -> Dict[str, "MultiResult"]:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ ignore = [
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
"ARG002", # Unused method argument
"B028", # No explicit `stacklevel` keyword argument found
"C419", # Unnecessary list comprehension
"COM812", # Trailing comma missing
"FBT001", # Boolean-typed positional argument in function definition
"FBT002", # Boolean default positional argument in function definition
Expand Down

0 comments on commit aab274a

Please sign in to comment.