Skip to content

Commit 72623d7

Browse files
authored
Merge pull request #758 from opsmill/pog-combine-if-statements
Combine if statements
2 parents 5858284 + fc7c89a commit 72623d7

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
@@ -358,11 +358,12 @@ def _strip_unmodified(self, data: dict, variables: dict) -> tuple[dict, dict]:
358358
relationship_property = getattr(self, relationship)
359359
if not relationship_property or relationship not in data:
360360
continue
361-
if not relationship_property.initialized and (
362-
not isinstance(relationship_property, RelatedNodeBase) or not relationship_property.schema.optional
363-
):
364-
data.pop(relationship)
365-
elif isinstance(relationship_property, RelationshipManagerBase) and not relationship_property.has_update:
361+
if (
362+
not relationship_property.initialized
363+
and (
364+
not isinstance(relationship_property, RelatedNodeBase) or not relationship_property.schema.optional
365+
)
366+
) or (isinstance(relationship_property, RelationshipManagerBase) and not relationship_property.has_update):
366367
data.pop(relationship)
367368

368369
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
@@ -261,7 +261,6 @@ ignore = [
261261
"SIM105", # Use `contextlib.suppress(KeyError)` instead of `try`-`except`-`pass`
262262
"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
263263
"SIM110", # Use `return any(getattr(item, resource_field) == resource_id for item in getattr(self, RESOURCE_MAP[resource_type]))` instead of `for` loop
264-
"SIM114", # Combine `if` branches using logical `or` operator
265264
"TC003", # Move standard library import `collections.abc.Iterable` into a type-checking block
266265
"UP031", # Use format specifiers instead of percent format
267266
]

0 commit comments

Comments
 (0)