Repository navigation
chore: add type annotations to DataSourceOVF - #7148
anujsingh-cse wants to merge 4 commits into
Conversation
Removing cloudinit.sources.DataSourceOVF from the mypy override list in pyproject.toml surfaces six errors. The transports list joins two functions with different signatures into an uncalled object type; annotate it as a list of (name, no-arg callable returning Optional[str]) tuples. The loop also no longer pre-binds name to None: name is only read when one of the calls produced contents, so the loop-bound str is always defined there. seedfound starts as a bool and is then assigned the matched proto string; start it as Optional[str], which keeps the falsy checks identical. find_child builds an empty list of minidom nodes; annotate it. get_properties reads documentElement, which typeshed types as Optional, directly for localName and hasChildNodes. Read it once into a local and fold the impossible None case into the existing "No Environment Node" XmlError, so both reads are narrowed. 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.
86f56e1 to
a8a89c8
Compare
|
Rebased onto current main and fixed the check_format failure: the ISC004 lint errors were introduced to main by #6958 (implicitly concatenated strings in the test_azure_helper.py parametrize), and the merge-ref CI inherited them. The two concatenations are now parenthesized (a8a89c8); ruff 0.16.2 passes on the whole tree. The OVF changes themselves were already green. |
nryanl
left a comment
There was a problem hiding this comment.
See review comment in #7118 regarding duplicate changes in tests/unittests/sources/test_azure_helper.py.
Cover the datasource, XML helpers and transport functions. The get_ovf_env sentinel is typed as Literal[False] so transport callers keep their `is not False` contract while the seed path narrows to str. Malformed Property elements now raise XmlError instead of AttributeError, since minidom types the attribute map as optional.
|
Rebased onto current main by merge — head a2230de, no force-push after review. The duplicate All functions in Gates on this head: black 26.5.1, ruff and mypy clean. |
Proposed Commit Message
Additional Context
Refs GH-5445. Claimed in #5445 (comment).
Removing the module from the override list surfaces six errors:
npholds(transport name, callable)tuples whose two functionshave different signatures, so the join is not callable. Annotated
as
List[Tuple[str, Callable[[], Optional[str]]]](both transportsare zero-arg callable and return content or None). The pre-loop
name = Noneis dropped:nameis only read insideif contents:, which requires a loop iteration to have set both.seedfoundflips from a bool flag to the matched proto string;starting it as
Optional[str]keepsif not seedfound:identical.find_child's result list is annotatedList[minidom.Node].get_propertiesre-readsdocumentElement(Optional per typeshed)twice; it is now read once into a local and the impossible None
case is folded into the existing
"No Environment Node"XmlError.Test Steps
tox -e py3andtox -e check_formatto be confirmed by CI.Merge type