chore: fix most ty errors behind the infrahub_sdk/node/node.py override
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_checksumandupload_if_changed(async and sync), the checksum is now read withself._get_attribute("checksum"), which is typed asAttribute. The# type: ignore[union-attr]comments on the.valuereads are removed. Both__getattr__and_get_attributereturn the same object from_attribute_data, andFieldNotLoadedErroris still raised when.valueis read. is_resource_poolnow returns"CoreResourcePool" in getattr(self._schema, "inherit_from", []).- In both hierarchy query methods, the schema is narrowed with
isinstance(self._schema, NodeSchemaAPI)to gethierarchy_kind. The method returns early whenhierarchy_kindisNone, andhierarchy_kindis passed toschema.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 ignoresinvalid-argument-typeandunsupported-operator. Theunresolved-attributecomment now says 2 violations, inis_ip_prefixandis_ip_address.
How to review
- Check that the new
hierarchy_kind is Noneearly return matches the existing_hierarchy_supportcheck.supports_hierarchyis true only for aNodeSchemaAPIwhosehierarchyis set. - Check that the remaining override comment is accurate. With the override removed, ty reported 2
unresolved-attributeerrors, one each inis_ip_prefixandis_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