Skip to content

chore: add typing to cloudinit.distros.parsers hostname and resolv_conf#6909

Open
Ahmedaltu wants to merge 4 commits into
canonical:mainfrom
Ahmedaltu:typing/parsers-hostname
Open

chore: add typing to cloudinit.distros.parsers hostname and resolv_conf#6909
Ahmedaltu wants to merge 4 commits into
canonical:mainfrom
Ahmedaltu:typing/parsers-hostname

Conversation

@Ahmedaltu

Copy link
Copy Markdown

chore: add typing to cloudinit.distros.parsers hostname and resolv_conf

Add type annotations to fix check_untyped_defs mypy errors in:

  • cloudinit/distros/parsers/hostname.py
  • cloudinit/distros/parsers/resolv_conf.py

Use a _parsed flag to track parse state rather than checking truthiness
of _contents, since an empty list [] is a valid parsed result for empty
or comment-only input files.

Removes both modules from the mypy disabled list in pyproject.toml.

Fixes GH-5445

canonicalGH-5445

Signed-off-by: Ahmed <76178825+Ahmedaltu@users.noreply.github.com>
Signed-off-by: Ahmed <76178825+Ahmedaltu@users.noreply.github.com>
Signed-off-by: Ahmed <76178825+Ahmedaltu@users.noreply.github.com>

@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. Please merge the latest tip of main to pick up fixes for the failing tests.

def parse(self):
if self._contents is None:
def parse(self) -> None:
if not self._parsed:

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.

Rather than adding a new boolean can we just check if _parsed is truthey? Same comment throughout the rest of this PR.

@holmanb holmanb self-assigned this Jun 30, 2026
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.

[enhancement]: fix typing of untyped-defs

2 participants