docs: expand Python typing guide with real-world protocol examples - #1218
Open
iddocohen wants to merge 2 commits into
Open
docs: expand Python typing guide with real-world protocol examples#1218iddocohen wants to merge 2 commits into
iddocohen wants to merge 2 commits into
Conversation
Add a generators/transforms usage example (multi-kind filters with a typed list) and guidance to regenerate protocols on schema change and treat the generated file as a build artifact. Rewrite the overview opener as a capability lead.
Deploying infrahub-sdk-python with
|
| Latest commit: |
581d30e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://98ff6dfe.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://docs-python-typing-real-worl.infrahub-sdk-python.pages.dev |
ogenstad
reviewed
Jul 29, 2026
| from .protocols import NetworkDevice | ||
|
|
||
| # `kind` is the generated class, not a string, so attributes are type-checked | ||
| leaf_switches: list[NetworkDevice] = await client.filters( |
Contributor
There was a problem hiding this comment.
If this works as it should I'd expect this line to be:
leaf_switches = await client.filters(However I think we have a problem with all of the overloads on .filter and other functions in the sense that the unknown keyword arguments screw up the typing?
Contributor
Author
There was a problem hiding this comment.
Fixed by dropping the annotation to leaf_switches = await client.filters(...), since passing the class as kind is what produces the typed result. On the overloads, reveal_type confirms list[NetworkDevice] under both mypy and ty even with the filter kwargs present, so **kwargs: Any absorbs them without breaking resolution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enrich the Python SDK "Strict Typing in Python" guide. The page already documents the protocols mechanics; this adds the real-world usage and the "keep protocols in sync" framing that were missing.
Key changes
client.filters(kind=NetworkDevice, …)with alist[NetworkDevice]type hint) showing where protocols matter most.What needs reviewer attention
docs/docs/python-sdk/guides/python-typing.mdx(all other lines unchanged). New prose only; the example uses documented SDK APIs.What didn't change
infrahubctl protocolsreference page is auto-generated — untouched.Out of scope (deferred)
Test plan
cd docs && npm run buildsucceedsSummary by cubic
Expand the Python SDK typing guide with real-world
Protocolusage to catch schema mismatches before runtime, add a generator/transform example usingclient.filters(kind=NetworkDevice, ...)that inferslist[NetworkDevice](no redundant annotation), document regenerating protocols withinfrahubctl protocols, and update the overview to lead with capability.Written for commit 581d30e. Summary will update on new commits.