cloud-init
cloud-init copied to clipboard
chore: add type annotations to cloudinit.distros.parsers.hosts
Summary
Adds full type annotations to cloudinit/distros/parsers/hosts.py so it can be removed from the check_untyped_defs = false mypy override in pyproject.toml. Part of #5445.
- Replace the
None-sentinel_contentswith a_parsed: boolflag and an empty-list default, consistent with the approach used inresolv_conf.py(GH-6909), to avoid needingOptionaland narrowing asserts - Annotate all method signatures (parameter types and return types)
- Use
List,Tuple,Anyfromtypingfor Python 3.8 compatibility - Clean up the variable shadowing in
__str__wherepieceswas reassigned across incompatible types; use distinctraw_pieces/str_piecesnames instead - Change
add_entryto store option entries as a list rather than a tuple, keeping_contentstype consistent with what_parseproduces - Remove both
cloudinit.distros.parsers.hostsandtests.unittests.distros.test_hostsfrom the mypy override block
Test plan
- [ ] Existing tests in
tests/unittests/distros/test_hosts.pypass unchanged - [ ]
mypy cloudinit/distros/parsers/hosts.pyreports no errors