nullability
Pass nullable arguments that may not exist.
Usage
>>> Nullable(1).value
1
>>> print(Nullable(None).value)
None
>>> Nullable.if_not_none(1)
Nullable(value=1)
>>> print(Nullable.if_not_none(None))
None
Usecase example:
>>> from dataclasses import dataclass
>>> from typing import Optional
>>> from nullability import Nullable
>>> @dataclass
... class Foo:
... bar: Optional[int]
... baz: Optional[int]
...
... def update(
... self,
... bar: Optional[Nullable[int]]=None,
... baz: Optional[Nullable[int]]=None,
... ):
... if bar:
... self.bar = bar.value
... if baz:
... self.baz = baz.value
... return self
>>> foo = Foo(bar=1, baz=2)
>>> foo.update(bar=Nullable(3))
Foo(bar=3, baz=2)
>>> foo.update(baz=Nullable(None))
Foo(bar=3, baz=None)
>>> foo.update(bar=Nullable.if_not_none(None))
Foo(bar=3, baz=None)
>>> foo.update(bar=Nullable.if_not_none(4))
Foo(bar=4, baz=None)
Metadata
Release files for nullability 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nullability-0.1.1.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nullability-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.0 kB
Release files / nullability-0.1.1.tar.gz
| Download URL | nullability-0.1.1.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c8d49016a1e299779aa0d306fab037d87f8b84cba9576e769b03d0eff3cf7027
|
|
BLAKE2b-256 checksum How to use checksums |
590c5aca5db810d992dd1f9235cb2eccfaa123bed4b6fcbc674697506c1b9453
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.13
|
Release files / nullability-0.1.1-py3-none-any.whl
| Download URL | nullability-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
251938c7d34813b840e73dae180d31c7f21e74b93f5502a6ebc23736761d2e45
|
|
BLAKE2b-256 checksum How to use checksums |
7fb0ef8ed598a71ca88c15e72ba54dc09aca763d4975136db4d68896a65b803d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.13
|