Repository navigation
chore: add type annotations to vmware imc config_file - #7098
anujsingh-cse wants to merge 3 commits into
Conversation
|
|
||
| config = configparser.ConfigParser() | ||
| config.optionxform = str | ||
| config.optionxform = str # type: ignore [method-assign, assignment] |
There was a problem hiding this comment.
Please include a comment documenting why this is needed.
There was a problem hiding this comment.
Added a comment above the line explaining why the ignore is needed (the documented configparser idiom for preserving key case, which mypy cannot express against a method type) — 0a37e72.
Follows review feedback: cover the module's public surface rather
than only the two errors check_untyped_defs surfaced.
NicConfigurator is now fully annotated: constructor parameters and
instance attributes, gen_* helpers, generate(), configure(), and
find_devices(). gen_dhcp4 keeps its Dict[str, Any] because the dict
holds both bools and a nested dict; empty collections that mypy
cannot infer get explicit annotations.
The new generate() return type exposes a pre-existing shadowing in
the vmware config tests: the loop variable `config` collided with
the Config instance once ethernets_dict became typed. Rename the
loop variable to nic_config and give the Optional .get("match") /
.get("dhcp4-overrides") chains a {} default, so the test module
stays clean once canonical#7098 removes its mypy override.
Refs canonicalGH-5445
Follows review feedback: cover the module's public surface rather
than only the two errors check_untyped_defs surfaced.
NicConfigurator is now fully annotated: constructor parameters and
instance attributes, gen_* helpers, generate(), configure(), and
find_devices(). gen_dhcp4 keeps its Dict[str, Any] because the dict
holds both bools and a nested dict; empty collections that mypy
cannot infer get explicit annotations.
The new generate() return type exposes a pre-existing shadowing in
the vmware config tests: the loop variable `config` collided with
the Config instance once ethernets_dict became typed. Rename the
loop variable to nic_config and give the Optional .get("match") /
.get("dhcp4-overrides") chains a {} default, so the test module
stays clean once canonical#7098 removes its mypy override.
Refs canonicalGH-5445
The new generate() return type exposes a pre-existing shadowing in
the vmware config tests: the loop variable `config` collided with
the Config instance once ethernets_dict became typed. Rename the
loop variable to nic_config and give the Optional .get("match") /
.get("dhcp4-overrides") chains a {} default, so the test module
stays clean once #7098 removes its mypy override.
Refs GH-5445
Removing cloudinit.sources.helpers.vmware.imc.config_file and
tests.unittests.sources.vmware.test_vmware_config_file from the mypy
override list in pyproject.toml surfaces six errors.
config_file.py: the standard configparser idiom
config.optionxform = str assigns a class to a method, which mypy flags
as both method-assign and assignment; this is intentional (disables
option lowercasing) and follows the existing ignore style used in
cloudinit/config/schema.py.
test_vmware_config_file.py: two assertions chain .get("nameservers").get(...)
which mypy sees as union-attr because dict.get returns Optional. Adding
the {} default keeps runtime behavior identical when the key is present
and makes the Optional case explicit.
Refs canonicalGH-5445
Per review: add a comment explaining why the ignore is needed. The assignment is the documented configparser idiom for preserving key case; mypy sees it as assigning a class to a method. 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.
7c40b86 to
8164d27
Compare
|
Rebased onto current main to clear the conflict with #7107 (both PRs edited the same mypy override list region). The pyproject resolution keeps both removals, and the shadowing/Optional test commit dropped from this branch since #7107 already carried the identical content upstream — the module now type-checks and passes against the merged state, as intended. Also carrying one lint fix so check_format is green on the fresh run: #6958 introduced two ISC004 (implicit string concatenation) errors in test_azure_helper.py on main, which every merge-ref CI run currently inherits; the two concatenations are parenthesized with no value change. Verified locally: |
Proposed Commit Message
Additional Context
Refs GH-5445. Claimed in #5445 (comment).
Removing both modules from the override list surfaces six errors:
config.optionxform = stris the documented configparser pattern forpreserving key case; mypy cannot express "assign the builtin
strasthe transform function" against the bound-method type, so it is
ignored with the same comment style already used at
cloudinit/config/schema.py:523..get("nameservers").get(...)chains wherethe first
.getisOptional. Supplying{}as the default makesthe chain total; when the key is present (as in every fixture used
here) behavior is unchanged.
No signatures change, so there is no effect on callers.
Test Steps
tox -e py3andtox -e check_formatto be confirmed by CI (developedon Windows where the full tox suite cannot run).
Merge type