Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/maybe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .maybe import (
Nothing,
NOTHING,
Some,
SomeNothing,
Maybe,
Expand All @@ -10,6 +11,7 @@

__all__ = [
"Nothing",
"NOTHING",
"Some",
"SomeNothing",
"Maybe",
Expand Down
1 change: 1 addition & 0 deletions src/maybe/maybe.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def ok_or_else(self, op: Callable[[], E]) -> result.Err[E]:
"""
return result.Err(op())

NOTHING = Nothing()

# Define Maybe as a generic type alias for use in type annotations
Maybe: TypeAlias = Union[Some[T], Nothing]
Expand Down
8 changes: 7 additions & 1 deletion tests/test_maybe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import Callable

from maybe.maybe import NOTHING
import pytest
import result

Expand Down Expand Up @@ -29,7 +30,12 @@ def test_eq() -> None:
assert Some(1) != "abc"
assert Some("0") != Some(0)


def test_const_nothing() -> None:
assert NOTHING == Nothing()
assert NOTHING.is_nothing() is True
assert Some(1) != NOTHING
assert len({Some(1), NOTHING}) == 2

def test_hash() -> None:
assert len({Some(1), Nothing(), Some(1), Nothing()}) == 2
assert len({Some(1), Some(2)}) == 2
Expand Down