Skip to content

chore: add type annotation to cloudinit.net.network_manager - #7120

Open
anujsingh-cse wants to merge 1 commit into
canonical:mainfrom
anujsingh-cse:fix/untyped-defs-network-manager-5445
Open

anujsingh-cse wants to merge 1 commit into
canonical:mainfrom
anujsingh-cse:fix/untyped-defs-network-manager-5445

Conversation

@anujsingh-cse

Copy link
Copy Markdown

Proposed Commit Message

chore: add type annotation to cloudinit.net.network_manager

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 GH-5445

Additional Context

Refs GH-5445. Claimed in #5445 (comment).

Removing the module from the override list surfaces two errors:

network_manager.py:56: error: Cannot assign to a method  [method-assign]
network_manager.py:56: error: Incompatible types in assignment
                (expression has type "type[str]",
                 variable has type "Callable[[str], str]")  [assignment]

self.config.optionxform = str is the documented configparser pattern
for 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

$ python -m mypy cloudinit/net/network_manager.py
(0 errors with the override removed)

$ pytest tests/unittests/net/test_network_manager.py -q
7 passed

$ ruff check / black --check / isort --check-only (target file)
All green

tox -e py3 and tox -e check_format to be confirmed by CI
(developed on Windows where the full tox suite cannot run).

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant