Add a `must` method that ensures a DaemonIdentity is a DaemonSubIdentity
in a single call.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
import pathlib
import re
-from typing import Union
+from typing import Union, Optional
from .context import CephadmContext
parent.daemon_id,
subcomponent,
)
+
+ @classmethod
+ def must(cls, value: Optional[DaemonIdentity]) -> 'DaemonSubIdentity':
+ """Helper to assert value is of the correct type. Mostly to make mypy
+ happy.
+ """
+ if not isinstance(value, cls):
+ raise TypeError(f'{value!r} is not a {cls}')
+ return value