Skip to content

Conversation

@holmanb
Copy link
Member

@holmanb holmanb commented Jan 15, 2026

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.

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.
@holmanb holmanb force-pushed the holmanb/mypy-stages branch from 71eab44 to ab13016 Compare January 15, 2026 01:05
@holmanb holmanb changed the title chore(stages): enable type annotations chore(stages): enable type checking Jan 15, 2026
Copy link
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.

LGTM. Just two minor nits:

  1. type hint on _get_per_boot_network_semaphore ... -> _Semaphore
  2. 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)
Copy link
Collaborator

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.

Copy link
Member Author

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]

Copy link
Collaborator

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

@holmanb holmanb merged commit b7b6256 into canonical:main Jan 23, 2026
22 checks passed
@holmanb holmanb deleted the holmanb/mypy-stages branch January 23, 2026 20:35
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.

2 participants