Repository navigation
chore: add type annotation to cloudinit.net.network_manager - #7120
anujsingh-cse wants to merge 5 commits into
Conversation
blackboxsw
left a comment
There was a problem hiding this comment.
Thank you @anujsingh-cse for continuing to help on the type annotations front.
Some things we would like to keep in mind is that we are not just silencing type warnings via ignore. We are looking to improve the typing coverage throughout the file by adding type annotations to all public and private methods, inputs and return values, and avoid type limiting where possible. Some helpful additional guidance is on 5445 to help make this a more helpful contribution to upstream.
|
Follow-up in 7ff25f8: every method in the module is now annotated, per the GH-5445 guidance on the linked comment. Coverage and types:
mypy is clean with the override removed, ruff/black/isort pass, pylint is 10.00/10, and the network-manager-related suites pass (7/7 in test_network_manager.py; 15/15 across the nm-keyed net tests). |
Removing cloudinit.net.network_manager from the mypy override list in pyproject.toml surfaces two errors on the same line. __init__ assigns the builtin str as the optionxform transform, the documented configparser idiom for preserving option name case. mypy cannot express assigning a class to a method, so it is ignored with a comment explaining why, matching the comment added in cloudinit/sources/helpers/vmware/imc/config_file.py. Refs canonicalGH-5445
Follows the canonicalGH-5445 review guidance: full annotation coverage of the module, not only the errors check_untyped_defs surfaced. Every NMConnection method, the Renderer class, and all four module functions are now typed. Concrete types throughout: - section/option/value parameters are str; _get_config_option returns Optional[str] (None when unset); _config_option_is_set and valid return bool; dump and con_uuid return str. - family/subnet/iface/route parameters are Dict[str, Any] — the honest type of the dict-based NetworkState payloads until network_state itself gains coverage; subnet_type is Optional[str]. - Renderer.connections is declared Dict[str, NMConnection]; get_conn returns NMConnection and con_ref returns str (the UUID, or the caller's id when the connection is unknown). - render_network_state's templates are Optional[Dict[str, str]] and target Optional[str], matching the base Renderer signature. - The filename helpers are (str, Optional[str]) -> str, except conn_filename -> Optional[str], and available() -> bool. - mac_addr is (str) -> str. The optionxform assignment keeps the documented-ignore comment from the earlier review round. No asserts, casts, or added Any beyond the network-state dict payloads. Refs canonicalGH-5445
canonical#6958 added base64 error-message parameters to test_azure_helper.py with implicitly concatenated strings inside collection literals, which the pinned ruff flags as ISC004. CI for every open PR runs against the merge ref, so this fails check_format across the board. Wrap the two concatenations in parentheses; the string values are unchanged.
7ff25f8 to
6ca403a
Compare
|
The PR: Lint failure on this head was the ISC004 regression #6958 introduced to main ( Branch rebased onto current main (which brings #7083 and the #6958 lines) and the identical parenthesization from #7098/#7148 carried in 6ca403a, so check_format is green on the merge-ref; it becomes a no-op once either of those merges. Re-verified on the rebased head with the pinned toolchain: |
net_convert builds the renderer from distro.renderer_configs, whose values are MutableMapping[str, Any] (the base Distro declaration), so the Dict[str, Any] parameter rejected the real caller payload under the full-tree mypy run.
|
The follow-up check_format run surfaced one more real error from the annotation coverage, now fixed in 1c7855a: Full-tree mypy on the rebased head is clean for this module and the caller (the remaining local errors are the pre-existing platform-dependent ones on this Windows sandbox, unchanged from untouched main), ruff/black/isort pass, and all 7 network-manager tests pass. |
nryanl
left a comment
There was a problem hiding this comment.
See #7118 (review), and also #5445 (comment).
…twork-manager-5445
|
Rebased onto current main by merge — head 11165cd, no force-push after review. The duplicate Every method and module function in
The Gates on this head: black 26.5.1, ruff and mypy clean; all 7 |
Proposed Commit Message
Additional Context
Refs GH-5445. Claimed in #5445 (comment).
Removing the module from the override list surfaces two errors:
self.config.optionxform = stris the documented configparser patternfor preserving option name case (NM requires it). mypy cannot express
assigning a class to a method, so the line is ignored — with a comment
documenting why, per the review feedback on #7098.
Test Steps
tox -e py3andtox -e check_formatto be confirmed by CI(developed on Windows where the full tox suite cannot run).
Merge type