21 lines
465 B
Python
21 lines
465 B
Python
import abc
|
|
from typing import Generic, TypeVar
|
|
|
|
__all__ = ('Nullable',)
|
|
|
|
NullableType = TypeVar('NullableType')
|
|
|
|
|
|
class Nullable(Generic[NullableType], abc.ABC):
|
|
def null(self) -> bool:
|
|
"""must never change"""
|
|
raise NotImplementedError
|
|
|
|
def _resolve(self) -> NullableType:
|
|
"""if .null(), throw"""
|
|
raise NotImplementedError
|
|
|
|
def resolve(self) -> NullableType:
|
|
assert not self.null()
|
|
return self._resolve()
|