Skip to content

Type annotations in cloudinit.distros.Distros#6938

Open
rayterion wants to merge 12 commits into
canonical:mainfrom
rayterion:annotation/5445
Open

Type annotations in cloudinit.distros.Distros#6938
rayterion wants to merge 12 commits into
canonical:mainfrom
rayterion:annotation/5445

Conversation

@rayterion

@rayterion rayterion commented Jul 16, 2026

Copy link
Copy Markdown

Proposed Commit Message

refactor: add type hints for the distros module

as requested in #5445 

Additional Context

Test Steps

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

@holmanb

holmanb commented Jul 16, 2026

Copy link
Copy Markdown
Member

Please sign the CLA. Also, type annotations are only useful if they are used by mypy.

@rayterion

Copy link
Copy Markdown
Author

i've signed the CLA. I'll proceed by adding the types and checking them with mypy through tox.

@rayterion
rayterion marked this pull request as ready for review July 18, 2026 18:52
@rayterion

Copy link
Copy Markdown
Author

Note: mypy is still running into errors, so this PR is still not ready to merge

@rayterion

Copy link
Copy Markdown
Author

Update: I've successfully identified the issues and have finished the task.

@holmanb

holmanb commented Jul 20, 2026

Copy link
Copy Markdown
Member

It looks like tests are still failing.

@rayterion

rayterion commented Jul 20, 2026

Copy link
Copy Markdown
Author

I've run the formatting command:

tox -e do_format

I'll start fixing the failing tests now. I've already looked through them, and they seem easy to fix. They should be ready shortly.

@rayterion

Copy link
Copy Markdown
Author

I've identified the root cause of the failing tests and completed the fix.

The main issue was that I was using a feature introduced in Python 3.10—the union operator (|). As a result, the Python 3.9 tests were failing. I replaced all instances of the union operator with Python 3.9-compatible type annotations.

I'm now waiting for the workflow to complete to verify that everything passes successfully.

@rayterion

Copy link
Copy Markdown
Author

Everything's passing. It just needs a quick review now.

Comment thread cloudinit/distros/__init__.py Outdated
Comment thread cloudinit/distros/__init__.py Outdated
hostname_conf_fn = "/etc/hostname"
shadow_fn = "/etc/shadow"
shadow_extrausers_fn = "/var/lib/extrausers/shadow"
pip_package_name: str = "python3-pip"

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.

Is this actually required? Generally mypy infers the type from the assignment.

@rayterion rayterion Jul 24, 2026

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.

It's not exactly required for this variable because pip_package_name is always a string.

However, since some variables may be assigned to values of different types later on, i just chose to make it explicit for every one of them so that neither devs get confused nor mypy breaks somehow...

Whatever option you think is best, just let me know!

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.

Making it explicit for every one of them makes it more confusing - it makes me wonder why redundant type information would be necessary. The explicit type information is generally a requirement only when you are adding additional context (Option for example, tells mypy that this variable starts as NoneType and will later be assigned to another type).

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