chore: add type annotations to cloudinit.distros.opensuse - #7118
Open
anujsingh-cse wants to merge 1 commit into
Open
anujsingh-cse wants to merge 1 commit into
anujsingh-cse wants to merge 1 commit into
Conversation
Removing cloudinit.distros.opensuse and tests.unittests.distros.test_opensuse from the mypy override list in pyproject.toml surfaces errors in four places, all of them repeated instances of two problems. opensuse.preferred_ntp_clients fills the empty _preferred_ntp_clients attribute, which the base class declares without a type. Annotate it as Optional[List[str]] in cloudinit/distros/__init__.py, matching what the base property, ubuntu, and opensuse all store. test_opensuse.py builds its fixture through distros.fetch, whose return type is the base Distro; update_method and read_only_root are opensuse-specific attributes set in the subclass __init__, so the assignments mypy flags are on a base-class-typed fixture. Annotate the fixture as Any. Refs canonicalGH-5445
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Commit Message
Additional Context
Refs GH-5445. Claimed in #5445 (comment).
Removing both modules from the override list surfaces 23 errors, which
collapse into two problems:
opensuse.py:270andopensuse.py:276(plus the same shape inalpine.py:204, still overridden): the subclass property fills_preferred_ntp_clients, which the base class declares as a bare_preferred_ntp_clients = Noneatcloudinit/distros/__init__.py:145.mypy therefore types the attribute as
Noneand rejects everysubclass assignment of a list. The base property
(
__init__.py:654),ubuntu.py:54, andopensuse.pyall storelist[str]into it, so the declared type isOptional[List[str]].Annotating the declaration in the base class fixes every subclass at
once; no other module assigns or reads the private attribute.
test_opensuse.py(update_methodx18,read_only_rootx3): thefixture is built through
distros.fetch, annotated as returningType[Distro](the base class), whileupdate_methodandread_only_rootare opensuse-specific attributes set in the subclass__init__. The tests reset that state by assignment, so the fixtureis annotated
Anyrather than changing what is fetched or patched.No signatures change, so there is no effect on callers.
Test Steps
tox -e py3andtox -e check_formatto be confirmed by CI(developed on Windows where the full tox suite cannot run).
Merge type