py_nullable
Introduction
Python's None Wrapper, inspired by java.util.Optional
Getting Started
Installing
install from PyPI with:
python -m pip install py_nullable
install from source with:
git clone https://github.com/miyamo2theppl/py_nullable.git
cd py_nullable
python -m pip install .
Simple Usage
if you want to get value.
from py_nullable import Nullable
nullable: Nullable[str] = Nullable[str]("some string")
if nullable.isPresent():
print(nullable.get()) # Prints some string
if you want to generate a new Nullable from an existing Nullable with the mapping function.
from typing import Callable
from py_nullable import Nullable
nullable: Nullable[str] = Nullable[str]("1234")
callback: Callable[[str], int] = lambda x: int(x) * 2
result: Nullable[int] = nullable.map(callback)
print(result.get()) # Prints 2468
if you want to refactor the return value from Optional[T] to Nullable[T].
from yourpackage import YourClass
from py_nullable import Nullable, nullable_wrap
in_memory_db: dict[str, YourClass] = {"A001": YourClass("foo")}
@nullable_wrap
def find_by_id(id: str) -> Optional[YourClass]:
return in_memory_db.get(id)
nullable: Nullable[YourClass] = find_by_id("B001")
print(nullable.isEmpty()) # Prints True
Contributing
Create a feature branch
git checkout -b feature_{example}
Set up your environment
python -m venv .venv
.venv/bin/activate
pip install -r dev_requirements.txt
pip install -e .
Running Tests
pytest --cov py_nullable --cov-branch --cov-report=html
Metadata
Release files for py-nullable 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py_nullable-0.3.2.tar.gz | 10.7 kB | Without provenance | Details for py_nullable-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_nullable-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for py_nullable-0.3.2-py3-none-any.whl |
Total release size: 19.7 kB
Release files / py_nullable-0.3.2.tar.gz
| Download URL | py_nullable-0.3.2.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dcc92f74f68400682fac3f45473165942cdc60414d4d7c3c743a8569dfd09750
|
|
BLAKE2b-256 checksum How to use checksums |
c3c1b07c12e0f0b79dba194940d220a18e9a1a62da7272ba1ee932737bd53a80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / py_nullable-0.3.2-py3-none-any.whl
| Download URL | py_nullable-0.3.2-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
852b6364536fee34c5310164ed951775b9b2c61847e8dcec6e893fc8686934b9
|
|
BLAKE2b-256 checksum How to use checksums |
8eaca8c3f7963388d325fd554b29b8aa99ce9e6a528c099d1b2d1942f9664401
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for py-nullable 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.