Skip to main content

Sentinel Values - unique objects akin to None, True, False

Project description

Python package version Tests Status Documentation Status

sentinel-value is a Python package, that helps to create Sentinel Values - special singleton objects, akin to None, NotImplemented and Ellipsis.

It implements the sentinel() function (described by PEP 661), and for advanced cases it also provides the SentinelValue() class (not a part of PEP 661).

Usage example:

from sentinel_value import sentinel

MISSING = sentinel("MISSING")

def get_something(default=MISSING):
    ...
    if default is not MISSING:
        return default
    ...

Or, the same thing, but using the SentinelValue class (slightly more verbose, but allows to have nice type annotations):

from typing import Union
from sentinel_value import SentinelValue

class Missing(SentinelValue):
    pass

MISSING = Missing(__name__, "MISSING")

def get_something(default: Union[str, Missing] = MISSING):
    ...
    if default is not MISSING:
        return default
    ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sentinel-value-1.0.0.tar.gz (7.3 kB view hashes)

Uploaded Source

Built Distribution

sentinel_value-1.0.0-py3-none-any.whl (7.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page