Sentinel Values - unique objects akin to None, True, False
Project description
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("MISSING", __name__)
def get_something(default: Union[str, Missing] = MISSING):
...
if default is not MISSING:
return default
...
Links
Read the Docs: https://sentinel-value.readthedocs.io
GitHub repository: https://github.com/vdmit11/sentinel-value
Python package: https://pypi.org/project/sentinel-value/
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
Built Distribution
Hashes for sentinel_value-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddfb0d7fa122daa4b4c01c1fd4b646a75338a513a80143a3c86a72139690b059 |
|
MD5 | 88ea093b78f1c6186ccb5b7157a7c639 |
|
BLAKE2b-256 | df5066ae27c9ba6de6ace2606449a706f3c25fbfcdf72ddb6303009b687a1a2a |