Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

vdmit11/sentinel-value

Open more actions menu

Repository files navigation

sentinel-value

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
    ...

Links

About

Sentinel Values - unique global singleton objects, akin to None, NotImplemented and Ellipsis.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.