Provides an Undefined constant.
Project description
Py-Undefined
A light-weight dependency free library providing an Undefined
type to Python.
Install
Py-Undefined is on PyPI and can be installed with:
pip install py-undefined
Or with Poetry
poetry add py-undefined
Usage
The Undefined
class from this module can be used as a variable type and a value.
from py_undefined import Undefined
a: Undefined | int = Undefined
assert a is Undefined
Why?
This is very useful to web frameworks that need to distinguish between receiving null as a parameter value vs not receiving that parameter at all.
Example
# Framework that can now pass `Undefined` instead of `None` to method if param was absent from request.
@framework.method()
def update(a: int | Undefined, b: int | None | Undefined) -> None:
if a is not Undefined:
...
if b is not Undefined:
...
This allows for a client to use this method to update only what values are provided.
my_client.update(b=1) # Set b.
my_client.update(a=2) # Set a without setting b to None.
my_client.update(b=None) # b can be set to None explicitly.
Support The Developer
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
py-undefined-0.1.5.tar.gz
(6.8 kB
view details)
Built Distribution
File details
Details for the file py-undefined-0.1.5.tar.gz
.
File metadata
- Download URL: py-undefined-0.1.5.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.12 Linux/6.6.6-76060606-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ad7df6347e4dc3373e4e8f0bd89c0788edcf34cd4a84ae92cac067d898d82e0 |
|
MD5 | 561de9b5f998f0ca160f9b381c0de1a5 |
|
BLAKE2b-256 | 27de6eb784e4f834feb354f390f6799ebe688e3d22d8f2112da70bbd94a2c0ca |
File details
Details for the file py_undefined-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: py_undefined-0.1.5-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.12 Linux/6.6.6-76060606-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eac9ec57c3e3459924d39f07d41b65f8c160d8da3609dd4f6ac957720ef685e4 |
|
MD5 | 9389059a88c25074eb33ff02562e1898 |
|
BLAKE2b-256 | 7033dd7c255a9f3a218f5f46577be232da5f13963189f9c58a599124b123c534 |