diff --git a/optional/nothing.py b/optional/nothing.py index 98d61d0..5e8ac0b 100644 --- a/optional/nothing.py +++ b/optional/nothing.py @@ -1,18 +1,23 @@ from types import NotImplementedType -from typing import Any +from typing import final +from typing_extensions import override + +@final class Nothing: """Represents the absence of a value. Rarely instantiated on its own, see :func:`Optional.empty`""" - def __eq__(self, other: Any) -> bool | NotImplementedType: + @override + def __eq__(self, other: object) -> bool | NotImplementedType: if not isinstance(other, Nothing): return NotImplemented return True + @override def __repr__(self) -> str: return "Optional.empty()" diff --git a/optional/something.py b/optional/something.py index f99040b..40b89e8 100644 --- a/optional/something.py +++ b/optional/something.py @@ -1,9 +1,12 @@ from types import NotImplementedType -from typing import Any, Generic, TypeVar +from typing import Generic, TypeVar, final + +from typing_extensions import override T = TypeVar("T") +@final class Something(Generic[T]): """Represents the presence of a value. @@ -17,12 +20,14 @@ def __init__(self, value: T) -> None: self._value = value - def __eq__(self, other: Any) -> bool | NotImplementedType: + @override + def __eq__(self, other: object) -> bool | NotImplementedType: if not isinstance(other, Something): return NotImplemented return self._value == other._value + @override def __repr__(self) -> str: return f"Optional.of({self._value!r})"