Skip to content

test: pin the return types of the client's get and filters overloads - #1576

Open
saltas888 wants to merge 3 commits into
stablefrom
pha/INBOX-199
Open

saltas888 wants to merge 3 commits into
stablefrom
pha/INBOX-199

Conversation

@saltas888

@saltas888 saltas888 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

tests/unit/sdk/test_client_overload_types.py pins the types that get() and filters() return when a protocol class is passed as kind, for InfrahubClient and InfrahubClientSync, including calls with several filter keyword arguments, an unpacked dict[str, Any] of filters, and raise_when_missing. ty checks the module through the existing ty check . lint step. A unit test runs mypy on it (--follow-imports=silent), because CI runs mypy only over infrahub_sdk/. No production code, dependency or CI workflow changes.

Widening the protocol overloads of filters() to list[Any], or of get() to Any, makes 6 assertions fail under each checker. Two get() calls are left unpinned and listed in the module docstring, because both checkers already resolve them to a type callers would not want: get(kind=P, **filters) returns Any, and get(kind=P, raise_when_missing=flag) with a bool variable returns P instead of P | None. The test imports mypy directly instead of skipping when it is missing, so the guard cannot switch itself off; CI installs it with --all-groups.

Tracked as INBOX-199; the question it answers was raised in review of #1218.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

saltas888 and others added 3 commits December 2, 2026 11:16
Passing a generated protocol class as kind makes client.filters() and
client.get() return that class, even with arbitrary filter keyword
arguments. Only a one-off reveal_type check during review of #1218 showed
this. The new module asserts those types with assert_type(), for the
async and sync clients. ty checks it through the existing `ty check .`
lint step; a unit test runs mypy on it, because CI runs mypy only over
infrahub_sdk/.

Widening the filters() protocol overload to list[Any] makes both checks
fail.

Refs: INBOX-199

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add filters(kind=P, **filters) with a dict[str, Any], a positional string
kind for get(), and the guide's role__value plus include call. Run mypy
with --follow-imports=silent so the test reports only errors in its own
file: the mypy CI step already checks infrahub_sdk/, and the
dependency-lower-bounds job would otherwise check it against the lowest
dependency versions.

Refs: INBOX-199

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the explicit raise_when_missing=True overload for both clients, reuse
PYPROJECT_FILE from tests/constants.py, and state in the module docstring
which get() calls resolve to a type callers would not want and are
therefore not pinned: an unpacked filters dictionary (Any) and a bool
variable for raise_when_missing (the protocol type without None).

Refs: INBOX-199

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6195b5e
Status: ✅  Deploy successful!
Preview URL: https://1b2731fe.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pha-inbox-199.infrahub-sdk-python.pages.dev

View logs

@saltas888
saltas888 requested a review from a team as a code owner December 2, 2026 11:17

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

View guided diff | Turn on auto-fix | Re-trigger cubic

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##           stable    #1576      +/-   ##
==========================================
- Coverage   88.30%   87.89%   -0.41%     
==========================================
  Files         157      157              
  Lines       16310    15660     -650     
  Branches     2410     2114     -296     
==========================================
- Hits        14402    13765     -637     
- Misses       1332     1335       +3     
+ Partials      576      560      -16     
Flag Coverage Δ
integration-tests 43.00% <ø> (-0.67%) ⬇️
python-3.10 63.03% <ø> (-0.64%) ⬇️
python-3.11 63.03% <ø> (-0.64%) ⬇️
python-3.12 63.05% <ø> (-0.62%) ⬇️
python-3.13 63.05% <ø> (-0.63%) ⬇️
python-3.14 63.05% <ø> (-0.63%) ⬇️
python-3.15 63.04% <ø> (-0.64%) ⬇️
python-filler-3.12 23.03% <ø> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant