Repository navigation
chore: add type annotation to cloudinit.sources.helpers.azure - #7121
anujsingh-cse wants to merge 4 commits into
Conversation
Removing cloudinit.sources.helpers.azure from the mypy override list in pyproject.toml surfaces two errors in _decrypt_certs_from_xml. The Data element lookup feeds certificates_content, which is then encoded for the openssl call, and mypy sees both the Element and the text as Optional. Raise InvalidGoalStateXMLException when the Data element or its content is missing, matching the guard the caller already applies to an empty certificates XML, instead of crashing with an AttributeError deeper in the stack. 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.
7aee9f0 to
cd2a5c0
Compare
nryanl
left a comment
There was a problem hiding this comment.
See #7118 (review), and also #5445 (comment).
Annotate every function in cloudinit.sources.helpers.azure so the module no longer needs the check_untyped_defs exemption. GoalState now resolves required xpath values through a helper that returns str, preserving the existing InvalidGoalStateXMLException diagnostics without a cast or an assert. The property decode helper keeps an Any return because the value type varies per call site (str, bytes or bool); default stays Any for the same reason.
|
Rebased onto current main by merge — head bb5e480, no force-push after review. The duplicate All 33 functions in
The 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 two errors:
ET.fromstring(certificates_xml).find(".//Data")returns anOptional[Element], andElement.textis itselfOptional[str],feeding
certificates_content.encode(...)on the openssl call. Asingle guard now raises the module's own
InvalidGoalStateXMLExceptionwhen the Data element or content ismissing — the same exception the caller already raises for an empty
certificates XML (
azure.py:413) — instead of an uncaughtAttributeError deeper in the stack.
certificates_contentis usedonly once, so no other call sites are affected.
Test Steps
tox -e py3andtox -e check_formatto be confirmed by CI(developed on Windows where the full tox suite cannot run).
Merge type