Skip to content

chore(opennebula): enable mypy type checking#6827

Open
mcanevet wants to merge 2 commits intocanonical:mainfrom
mcanevet:fix/opennebula-enable-mypy
Open

chore(opennebula): enable mypy type checking#6827
mcanevet wants to merge 2 commits intocanonical:mainfrom
mcanevet:fix/opennebula-enable-mypy

Conversation

@mcanevet
Copy link
Copy Markdown

@mcanevet mcanevet commented Apr 2, 2026

Proposed Commit Message

chore(opennebula): enable mypy type checking

Add type annotations to DataSourceOpenNebula.py to address concerns
raised in PR #6810 about type checking being disabled for the
OpenNebula datasource.

Refs GH-6810

Additional Context

This is a prerequisite for merging PR #6810 which adds ETHx_ROUTES support.

Test Steps

  • mypy passes
  • unit tests pass (50/50)

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>)

Add type annotations to DataSourceOpenNebula.py to address concerns
raised in PR canonical#6810 about type checking being disabled for the
OpenNebula datasource.

Refs canonicalGH-6810
@mcanevet mcanevet force-pushed the fix/opennebula-enable-mypy branch from c4fac41 to 14ce1f0 Compare April 3, 2026 06:08
Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the work here trying to shore up type hinting on DataSourceOpenNebula.

While we are here, the areas of interest I would like to also see covered by type hints would also include:

  • parse_shell_config
  • get_field, OpenNebulaNetwork.get_* methods.

Hopefully that's something we can tackle here and unblock the other PRs you have up as they start to alter some of the behavior in this datasource.

Thank you again for your contributions!

Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking request changes upon the request for a little bit more type hint coverage here.


m_find_devs_with.side_effect = my_devs_with
util.find_devs_with = my_devs_with
util.find_devs_with = my_devs_with # type: ignore[assignment]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables mypy type checking for the OpenNebula datasource by removing it (and its unit test module) from the mypy check_untyped_defs = false override list, and updating the datasource implementation to satisfy stricter typing.

Changes:

  • Remove DataSourceOpenNebula and its unit tests from mypy overrides to enable type checking.
  • Add/adjust type annotations in DataSourceOpenNebula.py (and a couple of small test typing tweaks) to pass mypy.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
cloudinit/sources/DataSourceOpenNebula.py Adds type annotations and small typing-driven refactors to satisfy mypy.
pyproject.toml Removes OpenNebula modules from the mypy override list so they are type-checked.
tests/unittests/sources/test_opennebula.py Minor typing-related tweaks to keep unit tests passing under mypy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


m_find_devs_with.side_effect = my_devs_with
util.find_devs_with = my_devs_with
util.find_devs_with = my_devs_with # type: ignore[assignment]
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test assigns cloudinit.util.find_devs_with globally (util.find_devs_with = my_devs_with), which can leak into other tests and cause order-dependent failures. Since @mock.patch(DS_PATH + ".util.find_devs_with") already patches the function used by find_candidate_devs(), drop the global assignment (or restore the original in a finally/use monkeypatch).

Suggested change
util.find_devs_with = my_devs_with # type: ignore[assignment]

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@holmanb should I remove the assignment as Copilot suggests?

@mcanevet mcanevet force-pushed the fix/opennebula-enable-mypy branch from 2c0cba8 to cfe8ced Compare April 10, 2026 07:43
Add type annotations to parse_shell_config, get_field (with @overload),
and all OpenNebulaNetwork.get_* methods as requested. Replace assert-based
type narrowing with proper guards. Remove leaked global assignment in test
and revert unrelated cosmetic changes.

Refs canonicalGH-6810
@mcanevet mcanevet force-pushed the fix/opennebula-enable-mypy branch from cfe8ced to 308c58c Compare April 10, 2026 07:48
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.

4 participants