diff --git a/ops/model.py b/ops/model.py index 6405e7080..d03c4b584 100644 --- a/ops/model.py +++ b/ops/model.py @@ -1908,7 +1908,7 @@ def __init__(self, message: str = ''): self.message = message def __init_subclass__(cls): - StatusBase.register(cls) + StatusBase._register(cls) def __eq__(self, other: 'StatusBase') -> bool: if not isinstance(self, type(other)): @@ -1941,14 +1941,21 @@ def from_name(cls, name: str, message: str): @classmethod def register(cls, child: Type['StatusBase']): - """Register a Status for the child's name.""" + """.. deprecated:: 2.17.0 Deprecated - this was for internal use only.""" + warnings.warn( + 'StatusBase.register is for internal use only', DeprecationWarning, stacklevel=2 + ) + cls._register(child) + return child + + @classmethod + def _register(cls, child: Type['StatusBase']) -> None: if not (hasattr(child, 'name') and isinstance(child.name, str)): raise TypeError( f"Can't register StatusBase subclass {child}: ", 'missing required `name: str` class attribute', ) cls._statuses[child.name] = child - return child _priorities = { 'error': 5, diff --git a/test/test_model.py b/test/test_model.py index 1f0b6391c..015dbc0ee 100644 --- a/test/test_model.py +++ b/test/test_model.py @@ -830,6 +830,10 @@ class NoNameStatus(ops.StatusBase): # pyright: ignore[reportUnusedClass] class NonStringNameStatus(ops.StatusBase): # pyright: ignore[reportUnusedClass] name = None # pyright: ignore[reportAssignmentType] + def test_base_status_register_is_deprecated(self): + with pytest.deprecated_call(): + ops.StatusBase.register(ops.ActiveStatus) + def test_status_repr(self): test_cases = { "ActiveStatus('Seashell')": ops.ActiveStatus('Seashell'),