Skip to main content

Pass nullable arguments that may not exist

Project description

nullability

Pass nullable arguments that may not exist.

PyPI version

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)

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

nullability-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

nullability-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file nullability-0.1.0.tar.gz.

File metadata

  • Download URL: nullability-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for nullability-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a746881b6a781f523f5ca705908f6a747308f3e833fe45f546432053749db914
MD5 4fd9ef0edbaf7445ce54e181ba3bf4c4
BLAKE2b-256 2195e55104505bf08b304ba378c38e89f69e519018eeb2285ceb53ff09574589

See more details on using hashes here.

File details

Details for the file nullability-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nullability-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for nullability-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19ce5724b002ce37459882969a53346366fed706c2deaf31c809dae9f37c6dde
MD5 de20fbf0edb57a811442f7b34a0c2c25
BLAKE2b-256 fd539c13c781327b907a3ff3d9e2f0e70a54ac18ebdfd61399de287b4d082aed

See more details on using hashes here.

Supported by

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