Sentinel for absent values.
Project description
🕳️ A Python library package which provides a sentinel for absent values - a falsey, immutable singleton that represents the absence of a value in contexts where None or False may be valid values.
Key Features ⭐
1️⃣ Absence Sentinel: A falsey singleton which represents absence.
🏭 Absence Factory: Create custom absence sentinels for package-specific or arbitrary needs.
𝒇 Predicate Functions: Determine if a value is absent.
🔍 Type Support: Type alias for optional values which may be absent. (Similar to typing.Optional and its relation to None.)
🌟 Builtins Integration: Can install singleton and predicate function into Python builtins.
Installation 📦
pip install absence
Examples 💡
Use the absent sentinel to represent missing values:
>>> from dataclasses import dataclass >>> from absence import absent, is_absent, Absential >>> @dataclass ... class User: ... name: str | None ... email: str | None >>> def apply_partial_update( ... user: User, ... name: Absential[ str | None ] = absent, ... email: Absential[ str | None ] = absent, ... ) -> User: ... ''' Updates user fields if values provided. ... ... Absent value means "don't change". ... None value means "clear field". ... ''' ... if not is_absent( name ): user.name = name ... if not is_absent( email ): user.email = email ... return user >>> user = User( name = 'Alice', email = 'alice@example.com' ) >>> # Clear name but leave email unchanged >>> updated = apply_partial_update( user, name = None ) >>> updated.name # Cleared to None >>> updated.email # Unchanged 'alice@example.com' >>> # Update both fields >>> updated = apply_partial_update( user, name = 'Bob', email = 'bob@example.com' ) >>> updated.name 'Bob' >>> updated.email 'bob@example.com'
Create package-specific absence sentinels:
>>> from absence import AbsenceFactory >>> MISSING = AbsenceFactory( ) >>> bool( MISSING ) False
Use Cases 🎯
🔄 Optional Arguments: When None is a valid argument value but you need to detect absence.
🎯 Sentinel Values: When you need a unique, falsey object to represent missing or invalid states.
🧩 Type Safety: When you want explicit typing for values that may be absent.
Comparison with Alternatives 🤔
Alternative |
Truthy? |
Unique? |
Picklable? |
Scope |
|---|---|---|---|---|
object() |
Yes |
Yes |
No |
Arbitrary |
PEP 661 Sentinels |
Optional |
Yes |
Yes |
Per-Module |
dataclasses.MISSING |
Yes |
Yes |
No |
Global |
typing.NoDefault |
Yes |
Yes |
Yes |
Global |
absence.absent |
No |
Yes |
No |
Global |
The absent sentinel combines falsey behavior with global uniqueness, making it particularly suitable for representing missing values in contexts where None might be a valid value. The companion AbsenceFactory allows creation of arbitrary absence sentinels, when needed, such as for specific packages.
See PEP 661 (“Sentinel Values”), typing.NoDefault, and dataclasses.MISSING for more details on alternatives.
More Flair
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file absence-1.0rc0.tar.gz.
File metadata
- Download URL: absence-1.0rc0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48a78ce2a328bbd963de390174aaf2d5ea117db469292e44715c02a6a5ceaffe
|
|
| MD5 |
bec5cb0b6222a0f76efa98a2f9590a35
|
|
| BLAKE2b-256 |
dc2c70a1bac539ce861f87b6479a376453d79dda4624375f736fa51b433b471e
|
Provenance
The following attestation bundles were made for absence-1.0rc0.tar.gz:
Publisher:
releaser.yaml on emcd/python-absence
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
absence-1.0rc0.tar.gz -
Subject digest:
48a78ce2a328bbd963de390174aaf2d5ea117db469292e44715c02a6a5ceaffe - Sigstore transparency entry: 157194027
- Sigstore integration time:
-
Permalink:
emcd/python-absence@73e91f39a81e77e98cc3e3a10101764874a4937b -
Branch / Tag:
refs/tags/v1.0rc0 - Owner: https://github.com/emcd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
releaser.yaml@73e91f39a81e77e98cc3e3a10101764874a4937b -
Trigger Event:
push
-
Statement type:
File details
Details for the file absence-1.0rc0-py3-none-any.whl.
File metadata
- Download URL: absence-1.0rc0-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4930e1a15d66a7c38f49fe1e8f375a4b5ed8bd537f1420f6eeb6422ad349f3a4
|
|
| MD5 |
1d216d52c6b38d6be1c842195d79f4fe
|
|
| BLAKE2b-256 |
089b53f12a0e491b510a0cf1aa5325ffd4bfea417b806c8ba3e3e5c006e77058
|
Provenance
The following attestation bundles were made for absence-1.0rc0-py3-none-any.whl:
Publisher:
releaser.yaml on emcd/python-absence
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
absence-1.0rc0-py3-none-any.whl -
Subject digest:
4930e1a15d66a7c38f49fe1e8f375a4b5ed8bd537f1420f6eeb6422ad349f3a4 - Sigstore transparency entry: 157194028
- Sigstore integration time:
-
Permalink:
emcd/python-absence@73e91f39a81e77e98cc3e3a10101764874a4937b -
Branch / Tag:
refs/tags/v1.0rc0 - Owner: https://github.com/emcd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
releaser.yaml@73e91f39a81e77e98cc3e3a10101764874a4937b -
Trigger Event:
push
-
Statement type: