Skip to content

Commit

Permalink
Make StatusName public (_StatusName -> StatusName)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-garner-canonical committed Sep 17, 2024
1 parent aabb970 commit 435e539
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions ops/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@

_ReadOnlyStatusName = Literal['error', 'unknown']
_SettableStatusName = Literal['active', 'blocked', 'maintenance', 'waiting']
_StatusName = Union[_SettableStatusName, _ReadOnlyStatusName]
_StatusDict = TypedDict('_StatusDict', {'status': _StatusName, 'message': str})
StatusName = Union[_SettableStatusName, _ReadOnlyStatusName]
_StatusDict = TypedDict('_StatusDict', {'status': StatusName, 'message': str})
_SETTABLE_STATUS_NAMES: Tuple[_SettableStatusName, ...] = get_args(_SettableStatusName)

# mapping from relation name to a list of relation objects
Expand Down Expand Up @@ -1878,10 +1878,10 @@ class StatusBase:
directly use the child class such as :class:`ActiveStatus` to indicate their status.
"""

_statuses: Dict[_StatusName, Type['StatusBase']] = {}
_statuses: Dict[StatusName, Type['StatusBase']] = {}

# Subclasses must provide this attribute
name: _StatusName
name: StatusName

def __init__(self, message: str = ''):
if self.__class__ is StatusBase:
Expand Down Expand Up @@ -1915,7 +1915,7 @@ def from_name(cls, name: str, message: str):
# unknown is special
return UnknownStatus()
else:
return cls._statuses[typing.cast(_StatusName, name)](message)
return cls._statuses[typing.cast(StatusName, name)](message)

@classmethod
def register(cls, child: Type['StatusBase']):
Expand Down
4 changes: 2 additions & 2 deletions ops/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
from ops._private import yaml
from ops.charm import CharmBase, CharmMeta, RelationRole
from ops.jujucontext import _JujuContext
from ops.model import Container, RelationNotFoundError, _NetworkDict, _StatusName
from ops.model import Container, RelationNotFoundError, _NetworkDict, StatusName
from ops.pebble import ExecProcess

ReadableBuffer = Union[bytes, str, StringIO, BytesIO, BinaryIO]
Expand All @@ -82,7 +82,7 @@
_RawStatus = TypedDict(
'_RawStatus',
{
'status': _StatusName,
'status': StatusName,
'message': str,
},
)
Expand Down
10 changes: 5 additions & 5 deletions test/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import ops
import ops.charm
from ops.model import ModelError, _StatusName
from ops.model import ModelError, StatusName

from .test_helpers import FakeScript, create_framework

Expand Down Expand Up @@ -965,11 +965,11 @@ def _on_collect_status(self, event: ops.CollectStatusEvent):
def test_collect_status_priority_valid(
request: pytest.FixtureRequest,
fake_script: FakeScript,
statuses: typing.List[_StatusName],
statuses: typing.List[StatusName],
expected: str,
):
class MyCharm(ops.CharmBase):
def __init__(self, framework: ops.Framework, statuses: typing.List[_StatusName]):
def __init__(self, framework: ops.Framework, statuses: typing.List[StatusName]):
super().__init__(framework)
self.framework.observe(self.on.collect_app_status, self._on_collect_status)
self.statuses = statuses
Expand Down Expand Up @@ -999,10 +999,10 @@ def _on_collect_status(self, event: ops.CollectStatusEvent):
def test_collect_status_priority_invalid(
request: pytest.FixtureRequest,
fake_script: FakeScript,
statuses: typing.List[_StatusName],
statuses: typing.List[StatusName],
):
class MyCharm(ops.CharmBase):
def __init__(self, framework: ops.Framework, statuses: typing.List[_StatusName]):
def __init__(self, framework: ops.Framework, statuses: typing.List[StatusName]):
super().__init__(framework)
self.framework.observe(self.on.collect_app_status, self._on_collect_status)
self.statuses = statuses
Expand Down

0 comments on commit 435e539

Please sign in to comment.