refactor: type the generated inventory as a group mapping - #70
Merged
cigamit merged 1 commit intoSep 13, 2026
Merged
Conversation
generate_inventory built one dict holding two unrelated shapes: `_meta`, whose value is host variables, and a group name per entry, whose value is hosts, children and vars. Indexing it meant the checker saw the union of both, so `inv_list[group]['hosts'].append(...)` read as `.append` on a dict and reported three unresolved attributes. The two shapes are now two variables. `groups` is a `dict[str, InventoryGroup]`, a TypedDict naming the three keys a group actually has, and `hostvars` is its own mapping. They are joined into the Ansible dynamic inventory format on the way out, `_meta` first and the groups in the order they were met, which is the order the single dict produced before. No behaviour change. `json_inventory` and `ini_inventory` return byte-identical output at 0, 1, 2, 9, 10, 11, 100 and 1000 hosts, the sizes that exercise the empty case, each group modulus and the by-10s, by-100s and by-1000s rollups. ty goes from 35 diagnostics to 32.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
cigamit
approved these changes
Sep 13, 2026
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.
generate_inventorybuilt one dict holding two unrelated shapes:_meta, whose value is host variables, and one entry per group name, whose value is hosts, children and vars. Indexing that dict means the checker sees the union of both, soinv_list[group]['hosts'].append(...)reads as.appendon a dict andtyreported three unresolved attributes for lines that are correct at runtime.The two shapes are now two variables:
They are joined into the Ansible dynamic inventory format on the way out,
_metafirst and the groups in the order they were met, which is the order the single dict produced before.Verification
No behaviour change, checked rather than reasoned about.
json_inventoryandini_inventoryreturn byte-identical output at 0, 1, 2, 9, 10, 11, 100 and 1000 hosts, compared againstmainfor each size. Those sizes exercise the empty case, each group modulus, the boundary either side of ten, and the by-10s, by-100s and by-1000s rollups that buildchildren.tygoes from 35 diagnostics to 32, which is these three and nothing else.ruff format --check,ruff checkand the unit suite (366 passing) are unchanged.Why this one and not the rest
Of the remaining type-checker findings this is the only one that is a single decision about a single structure. The others each need their own judgment, mostly about where
tycannot see throughself.__class__inpages/page.pyor a wideneddictinapi/client.py. None of them is a runtime bug, checked individually, and none is in this pull request.