singletons.sentinel

Pythonic FP - Collection of singleton classes

final class pythonic_fp.singletons.sentinel.Sentinel(sentinel_name: str)

Singleton classes representing sentinel values.

  • intended for library code, not to be exported/shared between modules

    • otherwise some of its intended typing guarantees may be lost

  • useful substitute for None as a hidden sentinel value

    • allows None to be stored in data structures

    • allows end users to choose to use None or () as sentinel values

    • always equals itself (unlike NoValue)

Usage:

  • import Sentinel and then either

    • define _my_sentinel: Final[Sentinel] = Sentinel('my_sentinel')

    • or use Sentinel('my_sentinel') directly

  • compare using either

    • is and is not or == and !=

    • the Sentinel() value always equals itself

    • and never equals anything else, especially other sentinel values