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 list comprehension #953

Merged
merged 1 commit into from
Jul 1, 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
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