Skip to content

Commit 156c35e

Browse files
authored
Linting: RUF021 Parenthesize a and b expressions when chaining and and or together (#6562)
1 parent 06cc74c commit 156c35e

File tree

9 files changed

+12
-11
lines changed

9 files changed

+12
-11
lines changed

backend/infrahub/cli/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ async def migrate_database(db: InfrahubDatabase, initialize: bool = False, check
326326
root_node.graph_version = migration.minimum_version + 1
327327
await root_node.save(db=db)
328328

329-
if not execution_result.success or validation_result and not validation_result.success:
329+
if not execution_result.success or (validation_result and not validation_result.success):
330330
rprint(f"Migration: {migration.name} {FAILED_BADGE}")
331331
for error in execution_result.errors:
332332
rprint(f" {error}")

backend/infrahub/core/query/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa
14691469

14701470
clean_filters = extract_field_filters(field_name=self.direction.value, filters=self.filters)
14711471

1472-
if clean_filters and "id" in clean_filters or "ids" in clean_filters:
1472+
if (clean_filters and "id" in clean_filters) or "ids" in clean_filters:
14731473
where_clause.append("peer.uuid IN $peer_ids")
14741474
self.params["peer_ids"] = clean_filters.get("ids", [])
14751475
if clean_filters.get("id", None):

backend/infrahub/core/query/relationship.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: # noqa: ARG
676676
where_clause = ['all(r IN rels WHERE r.status = "active")']
677677
clean_filters = extract_field_filters(field_name=self.schema.name, filters=self.filters)
678678

679-
if clean_filters and "id" in clean_filters or "ids" in clean_filters:
679+
if (clean_filters and "id" in clean_filters) or "ids" in clean_filters:
680680
where_clause.append("peer.uuid IN $peer_ids")
681681
self.params["peer_ids"] = clean_filters.get("ids", [])
682682
if clean_filters.get("id", None):

backend/infrahub/core/schema/definitions/internal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def to_dict(self) -> dict[str, Any]:
8282

8383
@property
8484
def optional_in_model(self) -> bool:
85-
if self.optional and self.default_value is None and self.default_factory is None or self.default_to_none:
85+
if (self.optional and self.default_value is None and self.default_factory is None) or self.default_to_none:
8686
return True
8787

8888
return False

backend/infrahub/core/schema/manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ async def update_node_in_db_based_on_diff(
471471
if diff_attributes:
472472
for item in node.local_attributes:
473473
# if item is in changed and has no ID, then it is being overridden from a generic and must be added
474-
if item.name in diff_attributes.added or item.name in diff_attributes.changed and item.id is None:
474+
if item.name in diff_attributes.added or (item.name in diff_attributes.changed and item.id is None):
475475
created_item = await self.create_attribute_in_db(
476476
schema=attribute_schema, item=item, branch=branch, db=db, parent=obj
477477
)
@@ -491,7 +491,9 @@ async def update_node_in_db_based_on_diff(
491491
if diff_relationships:
492492
for item in node.local_relationships:
493493
# if item is in changed and has no ID, then it is being overridden from a generic and must be added
494-
if item.name in diff_relationships.added or item.name in diff_relationships.changed and item.id is None:
494+
if item.name in diff_relationships.added or (
495+
item.name in diff_relationships.changed and item.id is None
496+
):
495497
created_rel = await self.create_relationship_in_db(
496498
schema=relationship_schema, item=item, branch=branch, db=db, parent=obj
497499
)

backend/infrahub/graphql/resolvers/many_relationship.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async def resolve(
9999
filters = {
100100
f"{info.field_name}__{key}": value
101101
for key, value in kwargs.items()
102-
if "__" in key and value or key in ["id", "ids"]
102+
if ("__" in key and value) or key in ["id", "ids"]
103103
}
104104

105105
response: dict[str, Any] = {"edges": [], "count": None}

backend/infrahub/graphql/resolvers/resolver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async def default_resolver(*args: Any, **kwargs) -> dict | list[dict] | None:
9999
filters = {
100100
f"{info.field_name}__{key}": value
101101
for key, value in kwargs.items()
102-
if "__" in key and value or key in ["id", "ids"]
102+
if ("__" in key and value) or key in ["id", "ids"]
103103
}
104104

105105
async with graphql_context.db.start_session(read_only=True) as db:
@@ -288,7 +288,7 @@ async def hierarchy_resolver(
288288
filters = {
289289
f"{info.field_name}__{key}": value
290290
for key, value in kwargs.items()
291-
if "__" in key and value or key in ["id", "ids"]
291+
if ("__" in key and value) or key in ["id", "ids"]
292292
}
293293

294294
response: dict[str, Any] = {"edges": [], "count": None}

backend/infrahub/graphql/resolvers/single_relationship.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async def _get_entities_simple(
107107
filters = {
108108
f"{field_name}__{key}": value
109109
for key, value in kwargs.items()
110-
if "__" in key and value or key in ["id", "ids"]
110+
if ("__" in key and value) or key in ["id", "ids"]
111111
}
112112
async with db.start_session(read_only=True) as dbs:
113113
objs = await NodeManager.query_peers(

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,6 @@ ignore = [
546546
"RUF010", # Use explicit conversion flag
547547
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
548548
"RUF015", # Prefer `next(...)` over single element slice
549-
"RUF021", # Parenthesize `a and b` expressions when chaining `and` and `or` together, to make the precedence clear
550549
"RUF029", # Function is declared `async`, but doesn't `await` or use `async` features.
551550
"RUF036", # `None` not at the end of the type annotation.
552551
"RUF043", # Pattern passed to `match=` contains metacharacters but is neither escaped nor raw

0 commit comments

Comments
 (0)