py-undefined 0.1.7

Last updated:

0 purchases

py-undefined 0.1.7 Image
py-undefined 0.1.7 Images
Add to Cart

Description:

pyundefined 0.1.7

Py-Undefined



A light-weight 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

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.