-
Notifications
You must be signed in to change notification settings - Fork 1k
chore(stages): enable type checking #6672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Init()'s initialization code is self-referential and has runtime ordering that prevents static analysis. Create a property Init.ds which only returns an initialized DataSource. This narrows the possible code paths that mypy must check and makes static analysis possible.
71eab44 to
ab13016
Compare
blackboxsw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just two minor nits:
- type hint on _get_per_boot_network_semaphore ... -> _Semaphore
- in your squashed commit, please note the included 'fix' to limit writing netcfg only when non-empty.
| self._write_network_config_json(netcfg) | ||
|
|
||
| if netcfg: | ||
| self._write_network_config_json(netcfg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unrelated to typing changes, but I agree we don't want to attempt to persist netcfg if it is empty or None, that'd cause a traceback in JSON marshaling within writE_network_config_json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unrelated to typing changes
That's not true. Undo this change and mypy spots the error:
cloudinit/stages.py:1092: error: Argument 1 to "_write_network_config_json" of "Init" has incompatible type "dict[Any, Any] | None"; expected "dict[Any, Any]" [arg-type]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh excellent. Thank you mypy! :)
Init()'s initialization code is self-referential and has runtime
ordering that prevents static analysis.
Create a property Init.ds which only returns an initialized DataSource.
This narrows the possible code paths that mypy must check and makes
static (and human) analysis possible.