Skip to content

typing: add type hints to cloudinit.temp_utils - #6939

Open
Prathamesh0901 wants to merge 4 commits into
canonical:mainfrom
Prathamesh0901:fix-temp-utils-typing
Open

typing: add type hints to cloudinit.temp_utils#6939
Prathamesh0901 wants to merge 4 commits into
canonical:mainfrom
Prathamesh0901:fix-temp-utils-typing

Conversation

@Prathamesh0901

Copy link
Copy Markdown

Proposed Commit Message

typing: add type hints to cloudinit.temp_utils

Adds type annotations to all functions in cloudinit/temp_utils.py
and removes the module from the check_untyped_defs exemption list
in pyproject.toml.

Also replaces a direct attribute assignment (fh.unlink = ...) with
setattr(), matching the existing pattern used for fh.unlink_now,
to resolve a mypy attr-defined error once strict checking applies
to this module.

Additionally adds an explicit Union[bool, str] annotation to
umount in cloudinit/util.py's mount_cb(), since correctly typing
temp_utils.tempdir()'s return value as Iterator[str] surfaced a
latent bool/str ambiguity that was previously masked by the
untyped default.

Refs GH-5445

Additional Context

Part of the ongoing effort tracked in #5445 to incrementally enable
check_untyped_defs across the codebase. This PR covers
cloudinit/temp_utils.py. The util.py change is a small, necessary
side effect (see commit message) rather than unrelated scope
creep -- happy to split it into a separate commit/PR if preferred.

No new tests added -- this is a type-only change with no
behavioral difference, verified by the existing test suite
passing unchanged.

Test Steps

.tox/mypy/bin/python -m mypy cloudinit/temp_utils.py
tox -e mypy
tox -e py3 -- tests/unittests/test_temp_utils.py
tox -e py3

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

@Prathamesh0901

Copy link
Copy Markdown
Author

please review @holmanb

@holmanb holmanb left a comment

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.

Thanks for this proposal. It looks like this is on track. I have a couple of minor nitpicks.

Comment thread cloudinit/temp_utils.py Outdated
Comment thread cloudinit/util.py Outdated
@Prathamesh0901
Prathamesh0901 requested a review from holmanb July 19, 2026 07:48
@Prathamesh0901

Copy link
Copy Markdown
Author

Hi @holmanb, just checking in, all checks are passing now after the changes. Let me know if anything else needs changing.

Comment thread cloudinit/util.py Outdated
Comment thread cloudinit/temp_utils.py
@Prathamesh0901
Prathamesh0901 requested a review from holmanb July 25, 2026 06:17
@Prathamesh0901

Copy link
Copy Markdown
Author

@holmanb I have made the changes mentioned in the last review.

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