Skip to main content

Package provided none-aware wrapper for none-safety object manipulation.

Project description

Python none-aware

Install

pip install none-aware

Usage

from none_aware import Maybe
obj = dict(foo='bar', baz=dict(foo='foo', bar='bar'))

maybe_obj = Maybe(obj)

assert maybe_obj['foo']() == 'bar'
assert maybe_obj['bar']() is None
assert maybe_obj['baz']['foo']() == 'foo'
assert maybe_obj['bar']['foo']() is None
assert maybe_obj['foo']['bar']() is None
assert maybe_obj.foo() == 'bar'
assert maybe_obj.bar() is None
assert maybe_obj.baz.foo() == 'foo'
assert maybe_obj.bar.foo() is None
assert maybe_obj.foo.bar() is None
assert maybe_obj.foo.upper() == 'BAR'
assert maybe_obj.foo.upper.lower() == 'bar'
assert maybe_obj.bar.foo.other.upper.lower() is None
assert maybe_obj.bar.foo.other.upper.lower.else_('Nothing') == 'Nothing'

maybe_strict = Maybe(obj, strict=True)
assert maybe_strict['foo'].else_('Other') == 'bar'
assert maybe_strict.foo.else_('Other') == 'Other'

maybe_none = Maybe(None)
print(maybe_none.foo.bar)  # None
print(maybe_none.is_none())  # True
print(maybe_none.bar.baz.is_none())  # True
print(maybe_obj.foo.is_none())  # False
print(maybe_obj.foo.bar.is_none())  # True

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

none-aware-0.0.2.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

none_aware-0.0.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file none-aware-0.0.2.tar.gz.

File metadata

  • Download URL: none-aware-0.0.2.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for none-aware-0.0.2.tar.gz
Algorithm Hash digest
SHA256 bf5f33029306aa9f6faeb48e738657beda079ea156b7606977689e59f20f33ce
MD5 75dc53e8cba2065ad8b63bc4b0b755e1
BLAKE2b-256 490479ea8c3514de770c97252736821a04463f44b5c1b290acce246a8243040e

See more details on using hashes here.

File details

Details for the file none_aware-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: none_aware-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for none_aware-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 91943829dd26b9258adb38de85520c5722c23bde43418a15c7baf091e7ef0ffe
MD5 e55d2ceb443b9466beaeb41324dd4072
BLAKE2b-256 d24f6c0e62f3cf98818769b9fe7b798408e5028983826e4099522b064d743e06

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