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.1.tar.gz (42.0 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.1-cp312-abi3-win_amd64.whl (156.8 kB view details)

Uploaded CPython 3.12+Windows x86-64

nofuture-1.2.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (298.1 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ x86-64

nofuture-1.2.1-cp312-abi3-macosx_11_0_arm64.whl (263.4 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

nofuture-1.2.1-cp312-abi3-macosx_10_12_x86_64.whl (266.0 kB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for nofuture-1.2.1.tar.gz
Algorithm Hash digest
SHA256 97597061303ebc62e3f6ad4f12ec385ce29e8067eee6d4f4e853c2ecdb4f69c1
MD5 8c9c963177594e11dd0deef442235b8b
BLAKE2b-256 62ea4c20176f67635e31707c31a18125d485e8d7a6d60458beccfdf19f05ece8

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.1.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.1-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: nofuture-1.2.1-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 156.8 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nofuture-1.2.1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 721287dfd3910cc8f5be84b930fa1f69574f816da4cb70c13589cdfd2c5884da
MD5 ee0d643776bdfc1f2b348e3e1847b89a
BLAKE2b-256 03908b98016b2e3ca417d4c4191153beafc8499a81cbccc84eb060a37d5ec47e

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.1-cp312-abi3-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.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nofuture-1.2.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6621b6eedada94a568a2e01152465efb459f7e4b4d6ec0841952f90debcad1de
MD5 7ce476481bce73fb9f63c157dea1ac29
BLAKE2b-256 695c286ff7d083e066e848afd9bd13beddd3b00ebd7c9687b4e5bea99d193ffa

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.1-cp312-abi3-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.

File details

Details for the file nofuture-1.2.1-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nofuture-1.2.1-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b81123762effefe71b2f18b21b943bcabd2212639768f68d48d2c8b7ad9fc8ba
MD5 8d6aaf0796492c1cd6caf2c38a8a5c58
BLAKE2b-256 8f00ce1c747ee0dfa41884dc16757a0a8d5b3851107a4bcbc7137620fd1c6207

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.1-cp312-abi3-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.1-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nofuture-1.2.1-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a8dc451e8282b68e5903b444c94850627ab8d4a0554835b42498616471d598b4
MD5 e2742ff566f612c0524b12d641a20305
BLAKE2b-256 ff9a7b1074b63b4d3e454712e109ef19c75f2fea06b8ba33cdd3fd339efb13c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.2.1-cp312-abi3-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.

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