Skip to content

typing: add type hints to cloudinit.distros.parsers.resolv_conf - #6997

Open
GoUrAv-MaLiK wants to merge 1 commit into
canonical:mainfrom
GoUrAv-MaLiK:type/resolv-conf
Open

typing: add type hints to cloudinit.distros.parsers.resolv_conf#6997
GoUrAv-MaLiK wants to merge 1 commit into
canonical:mainfrom
GoUrAv-MaLiK:type/resolv-conf

Conversation

@GoUrAv-MaLiK

@GoUrAv-MaLiK GoUrAv-MaLiK commented Aug 12, 2026

Copy link
Copy Markdown

Enables check_untyped_defs for cloudinit.distros.parsers.resolv_conf by annotating ResolvConf and removing it from the mypy override list in pyproject.toml.

self._contents is Optional; it is now narrowed with an assert after parse() before it is iterated or appended to. Behaviour is unchanged.

Refs GH-5445

  • I have signed the CLA
  • I have included a comprehensive commit message
  • I have added unit tests — N/A: typing-e class is already covered bytests/unittests/distros/test_resolv.py
  • I have kept the change small
  • I have added a reference to the related issue (Refs [enhancement]: fix typing of untyped-defs #5445)
  • I have updated the documentation — N/A

Proposed Commit Message

typing: add type hints to cloudinit.distros.

Annotate ResolvConf and enable check_untyped
removing it from the mypy override list in pyproject.toml.

self._contents is Optional; it is now narrowed with an assert after
parse() before it is iterated or appended to

Refs GH-5445

Additional Context

Part of the incremental effort in GH-5445 tomodule-by-module.

Test Steps

tox -e mypy    # clean (270 files, --platfor
tox -e py3 -- tests/unittests/distros/test_resolv.py tests/unittests/config/test_cc_resolv_conf.py   # 30 passed
tox -e ruff && tox -e black && tox -e isort

Merge type

  • Squash merge using "Proposed Commit Me

Annotate ResolvConf and enable check_untyped_defs for the module by
removing it from the mypy override list in pyproject.toml.

self._contents is Optional; it is now narrowed with an assert after
parse() before it is iterated or appended to. Behaviour is unchanged.

Refs canonicalGH-5445
@holmanb holmanb self-assigned this Aug 12, 2026
def local_domain(self, domain):
def local_domain(self, domain: str) -> str:
self.parse()
assert self._contents is not None

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.

While this technically is a form of type narrowing, it results in an exception when the assertion is fails.

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