chore(opennebula): enable mypy type checking#6827
chore(opennebula): enable mypy type checking#6827mcanevet wants to merge 2 commits intocanonical:mainfrom
Conversation
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
c4fac41 to
14ce1f0
Compare
blackboxsw
left a comment
There was a problem hiding this comment.
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!
blackboxsw
left a comment
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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
DataSourceOpenNebulaand 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] |
There was a problem hiding this comment.
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).
| util.find_devs_with = my_devs_with # type: ignore[assignment] |
There was a problem hiding this comment.
@holmanb should I remove the assignment as Copilot suggests?
2c0cba8 to
cfe8ced
Compare
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
cfe8ced to
308c58c
Compare
Proposed Commit Message
Additional Context
This is a prerequisite for merging PR #6810 which adds ETHx_ROUTES support.
Test Steps
Merge type