Skip to main content

NoFuture: explicit Maybe and Result types. No futures. No exceptions.

Project description

NoFuture

NoFuture

pipeline status

No futures. No exceptions. Just explicit values.

MayBe et Result pour Python, built en Rust (PyO3 + maturin).

Manifeste

Tu veux du safe ? Prends un try/except.

  • pas d'exceptions fantomes
  • pas de magie: tout est explicite
  • pas de futur promis: on assume Nothing / Err
from nofuture import MayBe, Result

Installation

pip install nofuture

Dev mode: maturin develop

MayBe

Valeur optionnelle: Just(value) ou Nothing.

MayBe.just(42)      # Just(42)
MayBe.nothing()     # Nothing

# API
.is_just() / .is_nothing()
.unwrap()                    # raise si Nothing
.expect(msg)                 # raise avec message custom si Nothing
.or_else(default)            # valeur ou default
.to_option()                 # valeur ou None
.map(fn)                     # Just(fn(x)) ou Nothing
.flat_map(fn)                # fn doit retourner MayBe
.match(just=fn, nothing=fn)  # pattern matching
>> fn                        # flat_map
| default                    # or_else
.__len__()                   # 1 si Just, 0 si Nothing
.__iter__()                  # itération sur 0/1 élément
.__bool__()                  # truthiness (Just -> True)
.__repr__()                  # "Just(x)" / "Nothing"
.__class_getitem__()         # support MayBe[T]

Result

Succès ou erreur: Ok(value) ou Err(message, code?, details?). La vie en binaire, avec du contexte.

Result.ok(42)
Result.err("not found", code="NOT_FOUND")
Result.err("validation", code="INVALID", details={"field": "name"})
Result.from_dict({"ok": True, "value": 42})  # réciproque de to_dict

# API
.is_ok() / .is_err()
.unwrap()              # raise si Err
.expect(msg)           # raise avec message custom si Err
.unwrap_or(default)    # valeur ou default
.unwrap_err()          # (msg, code, details) ou raise
.to_option()           # valeur ou None
.map(fn)               # Ok(fn(x)) ou Err passthrough
.map_err(fn)           # fn(msg, code, details) -> (msg, code, details)
.flat_map(fn)          # fn doit retourner Result
.and_then(fn)          # alias flat_map
.match(ok=fn, err=fn)  # pattern matching (err reçoit msg, code, details)
.to_dict()             # {"ok": True, "value": ...} ou {"ok": False, "error": ...}
>> fn                  # flat_map
| default              # unwrap_or
.__len__()             # 1 si Ok, 0 si Err
.__iter__()            # itération sur 0/1 élément
.__bool__()            # truthiness (Ok -> True)
.__repr__()            # "Ok(x)" / "Err('msg')"
.__class_getitem__()   # support Result[T, E]

Typage générique

MayBe et Result supportent la syntaxe générique pour le typage statique :

from nofuture import MayBe, Result
from typing import Any

# MayBe[T] pour les valeurs optionnelles
def find_user(id: int) -> MayBe[User]:
    ...

# Result[T, E] pour les opérations faillibles
MyResult = Result[dict[str, Any], str]

Itération

MayBe et Result se comportent comme des collections de 0 ou 1 élément :

len(MayBe.just(42))      # 1
len(MayBe.nothing())     # 0

for x in Result.ok("hi"):
    print(x)

value, = MayBe.just("ok")    # unpacking

Exemples

Quelques exemples concrets pour voir MayBe et Result en action :

  • base.py : les bases (construction, mapping, chaînage)
  • objects.py : intégration avec dataclasses et objets métier
  • result.py : pipelines d'erreurs et sérialisation
  • iteration.py : itération, unpacking, builtins
  • websocket_app.py + websocket_client.py : mini‑app complète

Tout le détail (dépendances, commandes, payloads, explications) est dans examples/README.md.

Tests

python3 -m unittest discover -s tests -p 'test_*.py'

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

nofuture-1.2.0.tar.gz (41.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nofuture-1.2.0-cp313-cp313-win_amd64.whl (155.1 kB view details)

Uploaded CPython 3.13Windows x86-64

nofuture-1.2.0-cp313-cp313-macosx_11_0_arm64.whl (262.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

nofuture-1.2.0-cp313-cp313-macosx_10_12_x86_64.whl (267.5 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

nofuture-1.2.0-cp312-cp312-win_amd64.whl (155.4 kB view details)

Uploaded CPython 3.12Windows x86-64

nofuture-1.2.0-cp312-cp312-macosx_11_0_arm64.whl (262.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nofuture-1.2.0-cp312-cp312-macosx_10_12_x86_64.whl (267.7 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

nofuture-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (304.2 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file nofuture-1.2.0.tar.gz.

File metadata

  • Download URL: nofuture-1.2.0.tar.gz
  • Upload date:
  • Size: 41.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nofuture-1.2.0.tar.gz
Algorithm Hash digest
SHA256 8772d8d3a81933de8b2ac7e06f1f6a06375b0b0db8c00ea5a41f189554c4f968
MD5 407b995aafdd462f078ac5103a83892e
BLAKE2b-256 8ddc1fa6f38633b2d5cb45e0e3a5bfaccd27b471aaf7930af5dd7e2690cfa4e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.0.tar.gz:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nofuture-1.2.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: nofuture-1.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 155.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nofuture-1.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7b1d68507cea337f9094e1f9028184ed641aaa485f2312bd360b35e9caedcc39
MD5 a9606ceb5b54ea5b08b4edddd62eee31
BLAKE2b-256 03d07f984fadf68feea4b7b26b6d4f9124f6dd79950577a0f8ed5f9fe34df31a

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.0-cp313-cp313-win_amd64.whl:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nofuture-1.2.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nofuture-1.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 82b01fc7103df82b5d0c70c8815a15de66c70025a8f99ad3258251e5acdbaeb6
MD5 131973fcdcb299cd910948dd953fe4e2
BLAKE2b-256 23d1bfead56ffcce54a0261ee07bcd6dd2471d9a8bc91c98cd8ff6d1e7b6271d

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nofuture-1.2.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nofuture-1.2.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d52ea19c1463fd890903f94ba518a4af560a48ecbbab382959b49750e46b0edc
MD5 321db8d6ccbcf26fca7a841d2c18cb93
BLAKE2b-256 9d98863dcd07208297b256b8b35c7fab1d6b1a853b25e50759fa7b699eface8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.0-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nofuture-1.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: nofuture-1.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 155.4 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nofuture-1.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 807c885a250e1d7ce799c2ec6a7b7c306748f8ee5b07cca62e0976434be2f95a
MD5 d863476c1d32c48dbaf95c9aa8a695c2
BLAKE2b-256 191d8793a57577cc93501674a43c53891ad2f7adec96b60a9be8b1137a83972b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.0-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nofuture-1.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nofuture-1.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cc7e8f597924c9883941d771897099403bb8e2da73e89ac98f751a655ec74ef4
MD5 1f4de7ed8864e561afb85c412f8adfd1
BLAKE2b-256 849f16437c4d61e52e4d57241e5a053173f2e89c18b790922c6a073298779c5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nofuture-1.2.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nofuture-1.2.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e96d6f3106cb3234cac22fdd7f0cee6cf112684bb65ef2a079c5c405a8433bac
MD5 b93af0125f0253fbcd613038b018020a
BLAKE2b-256 0290d0965318897d9a204e7cdbdb04901d6d743ea098cd38041564450e8011ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.0-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nofuture-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nofuture-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cfcad50529166eed1d49168720fdf386c12a3b356ec0e93ef3675640831c185d
MD5 b8cefe5a0004667a9c5d9b19d9223367
BLAKE2b-256 e20c4f9066d8a986554bae060b43df5de17ca8fb0761dc78e3cfe94d55560a75

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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