Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type casting to fix failing mypy lint #33

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
)
from ops.framework import StoredState
from ops.main import main
from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus
from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, StatusBase
from storage_connector import metrics_utils, nrpe_utils

import utils # noqa
Expand Down Expand Up @@ -158,7 +158,8 @@ def __init__(self, *args: Any) -> None:

def _on_install(self, _: InstallEvent) -> None:
"""Handle install state."""
self.unit.status = MaintenanceStatus("Installing charm software")
# type casting is to keep mypy happy; see https://github.com/canonical/operator/issues/1401
self.unit.status = cast(StatusBase, MaintenanceStatus("Installing charm software"))
if self._check_if_container():
return

Expand Down Expand Up @@ -199,7 +200,8 @@ def _render_config(self, _: ConfigChangedEvent) -> None:
if self._check_if_container():
return

self.unit.status = MaintenanceStatus("Validating charm configuration")
# type casting is to keep mypy happy; see https://github.com/canonical/operator/issues/1401
self.unit.status = cast(StatusBase, MaintenanceStatus("Validating charm configuration"))
self._check_mandatory_config()
if isinstance(self.unit.status, BlockedStatus):
return
Expand All @@ -209,7 +211,8 @@ def _render_config(self, _: ConfigChangedEvent) -> None:
if isinstance(self.unit.status, BlockedStatus):
return

self.unit.status = MaintenanceStatus("Rendering charm configuration")
# type casting is to keep mypy happy; see https://github.com/canonical/operator/issues/1401
self.unit.status = cast(StatusBase, MaintenanceStatus("Rendering charm configuration"))
self._create_directories()

tenv = Environment(loader=FileSystemLoader("templates"))
Expand Down