Skip to content
Open
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
11 changes: 10 additions & 1 deletion NodeKit/json_nodes/attributes/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ def _get_item_info(item: Any) -> list[str]:


def _get_pointer(element: Any) -> str:
return element["uuid"] if element else None
if not element:
return None

try:
return element.get("uuid")
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using element.get("uuid") without a default value returns None when the key doesn't exist, but this could mask the case where the uuid value itself is intentionally None. Consider using element.get("uuid", None) explicitly or handle the distinction between missing keys and None values.

Suggested change
return element.get("uuid")
return element.get("uuid", None)

Copilot uses AI. Check for mistakes.
except AttributeError:
try:
return element["uuid"]
except (KeyError, TypeError):
return None


Comment on lines +44 to 53
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic flow is unnecessarily complex. Consider checking if the element has dictionary-like behavior first, then use .get() with a default value. This would be more readable: return getattr(element, 'get', lambda k, default=None: element.get(k, default) if hasattr(element, 'get') else element.get(k) if k in element else default)('uuid') or simply use a more straightforward approach with hasattr checks.

Suggested change
try:
return element.get("uuid")
except AttributeError:
try:
return element["uuid"]
except (KeyError, TypeError):
return None
if hasattr(element, "get"):
return element.get("uuid", None)
elif isinstance(element, dict) and "uuid" in element:
return element["uuid"]
elif hasattr(element, "__getitem__") and "uuid" in element:
try:
return element["uuid"]
except Exception:
return None
return None

Copilot uses AI. Check for mistakes.
def _set_items(element, name, value):
Expand Down