Skip to main content

Sentinel value for missing data where None has its own meaning

Project description

no-value

PyPI Python Tests License

Sentinel value to express missing keys or values where None has its own meaning.

Why?

When building APIs or update operations, you often need to distinguish between:

  • a value — set the field
  • None — clear the field
  • not provided — leave the field unchanged

Python's None can't cover both "clear" and "not provided". NoValue fills that gap.

Installation

pip install no-value

Usage

from no_value import NoValue


def update_user(name: str | None | NoValue = NoValue) -> None:
    if name is NoValue:
        pass  # not provided, do nothing
    elif name is None:
        clear_name()  # explicitly set to null
    else:
        set_name(name)  # update with new value

Behavior

  • Use is for comparison: val is NoValue
  • str(NoValue) and repr(NoValue) return "NoValue"
  • NoValue() raises TypeError — it cannot be instantiated
  • bool(NoValue) raises TypeError — to prevent accidental truthy/falsy checks

Limitations

Static analysis tools (mypy, pyright) do not fully support custom sentinel types. Type annotations like str | None | NoValue work at runtime but may produce warnings in strict mode.

License

MIT

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

no_value-1.0.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

no_value-1.0.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file no_value-1.0.0.tar.gz.

File metadata

  • Download URL: no_value-1.0.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for no_value-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a42e471581a043ace99038a6ae0f38f994d13f9a5ba6196ad3298b4f06943193
MD5 569879ceaaa82197d85196c43ae63997
BLAKE2b-256 e694857e3e987a1b8100df299efb2ac54f5fae8e854cc31860c4ea281986120c

See more details on using hashes here.

Provenance

The following attestation bundles were made for no_value-1.0.0.tar.gz:

Publisher: publish-pypi.yml on miriada-io/no-value

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file no_value-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: no_value-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for no_value-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 830d356747ed04b6802c33a2aaefe32a15da7fd8720915ad614231c548a7812e
MD5 d38ea6773d32017edbb4b3ef2905e83a
BLAKE2b-256 878aba20ef5a872c66a3734c08542e890888613d4afa844cb1f83e069a32885a

See more details on using hashes here.

Provenance

The following attestation bundles were made for no_value-1.0.0-py3-none-any.whl:

Publisher: publish-pypi.yml on miriada-io/no-value

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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