chore: fix most ty errors behind the infrahub_sdk/node/node.py override

Merged
OG
1d ago
+29-28

This pull request was written by nisse, an AI agent, and opened with the GitHub account of the person who runs it. That person reviews it before marking it ready for review.

Why

The [[tool.ty.overrides]] section for infrahub_sdk/node/node.py turned off invalid-argument-type, unresolved-attribute and unsupported-operator, so ty did not report errors in that file. Most of those violations can be fixed without changing what the code does.

Non-goals: is_ip_prefix and is_ip_address are unchanged. Fixing them would change what they return for a generic schema.

What changed

No behaviour changes.

  • In download_file, matches_local_checksum and upload_if_changed (async and sync), the checksum is now read with self._get_attribute("checksum"), which is typed as Attribute. The # type: ignore[union-attr] comments on the .value reads are removed. Both __getattr__ and _get_attribute return the same object from _attribute_data, and FieldNotLoadedError is still raised when .value is read.
  • is_resource_pool now returns "CoreResourcePool" in getattr(self._schema, "inherit_from", []).
  • In both hierarchy query methods, the schema is narrowed with isinstance(self._schema, NodeSchemaAPI) to get hierarchy_kind. The method returns early when hierarchy_kind is None, and hierarchy_kind is passed to schema.get(kind=...) and _build_hierarchy_query_data(peer_kind=...). The type-ignore comments on those lines are removed.
  • In pyproject.toml, the node.py section no longer ignores invalid-argument-type and unsupported-operator. The unresolved-attribute comment now says 2 violations, in is_ip_prefix and is_ip_address.

How to review

  • Check that the new hierarchy_kind is None early return matches the existing _hierarchy_support check. supports_hierarchy is true only for a NodeSchemaAPI whose hierarchy is set.
  • Check that the remaining override comment is accurate. With the override removed, ty reported 2 unresolved-attribute errors, one each in is_ip_prefix and is_ip_address.

How to test

uv run ty check .
uv run mypy --show-error-codes infrahub_sdk
uv run invoke format lint-code
uv run pytest tests/unit/sdk/test_node.py tests/unit/sdk/test_file_object.py tests/unit/sdk/test_hierarchical_nodes.py tests/unit/sdk/test_node_only_access.py

All of these passed locally. The test run reported 585 passed.

Impact & rollout

  • Backward compatibility: No changes to the public API or to behaviour.

Checklist

  • Tests added/updated
  • Changelog entry added (uv run towncrier create ...)
  • External docs updated (if user-facing or ops-facing change)
  • Internal .md docs updated (internal knowledge and AI code tools knowledge)

No changelog fragment was added because users cannot see this change.

šŸ¤– Generated with Claude Code

Jira: IHS-321