Skip to content

Commit fc7c89a

Browse files
committed
Combine if statements
1 parent 2d1b586 commit fc7c89a

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

infrahub_sdk/node/node.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,12 @@ def _strip_unmodified(self, data: dict, variables: dict) -> tuple[dict, dict]:
355355
relationship_property = getattr(self, relationship)
356356
if not relationship_property or relationship not in data:
357357
continue
358-
if not relationship_property.initialized and (
359-
not isinstance(relationship_property, RelatedNodeBase) or not relationship_property.schema.optional
360-
):
361-
data.pop(relationship)
362-
elif isinstance(relationship_property, RelationshipManagerBase) and not relationship_property.has_update:
358+
if (
359+
not relationship_property.initialized
360+
and (
361+
not isinstance(relationship_property, RelatedNodeBase) or not relationship_property.schema.optional
362+
)
363+
) or (isinstance(relationship_property, RelationshipManagerBase) and not relationship_property.has_update):
363364
data.pop(relationship)
364365

365366
for item in original_data:

infrahub_sdk/store.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ def _get_by_id(self, id: str, kind: str | None = None) -> InfrahubNode | Infrahu
165165
def _get_by_hfid(
166166
self, hfid: str | list[str], kind: str | None = None
167167
) -> InfrahubNode | InfrahubNodeSync | CoreNode | CoreNodeSync:
168-
if not kind:
169-
node_kind, node_hfid = parse_human_friendly_id(hfid)
170-
elif kind and isinstance(hfid, str) and hfid.startswith(kind):
168+
if not kind or (kind and isinstance(hfid, str) and hfid.startswith(kind)):
171169
node_kind, node_hfid = parse_human_friendly_id(hfid)
172170
else:
173171
node_kind = kind

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ ignore = [
262262
"SIM105", # Use `contextlib.suppress(KeyError)` instead of `try`-`except`-`pass`
263263
"SIM108", # Use ternary operator `key_str = f"{value[ALIAS_KEY]}: {key}" if ALIAS_KEY in value and value[ALIAS_KEY] else key` instead of `if`-`else`-block
264264
"SIM110", # Use `return any(getattr(item, resource_field) == resource_id for item in getattr(self, RESOURCE_MAP[resource_type]))` instead of `for` loop
265-
"SIM114", # Combine `if` branches using logical `or` operator
266265
"TC003", # Move standard library import `collections.abc.Iterable` into a type-checking block
267266
"UP031", # Use format specifiers instead of percent format
268267
]

0 commit comments

Comments
 (0)