Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Feature Request: Convenience constructor for Result

Aperta
#1,627 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

Inizia leggendo i costruttori Result esistenti e l’implementazione di Maybe.from_optional menzionata nell’issue. Analizza come un costruttore basato su un callable potrebbe rappresentare le eccezioni mantenendo il supporto per i tipi di errore generali, quindi individua i test pertinenti. Il lavoro è completato quando il design dell’API è definito e il suo comportamento e tipaggio sono coperti dai test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Hello! Apologies for filing as a "bug" but didn't see another issue type I could file as.

I was wondering if there was any appetite for an additional constructor on Result that would implement something akin to Scala's Try constructor (e.g. https://alvinalexander.com/scala/try-success-failure-example-reading-file/)

As a very primitive example, I often use a utility function that looks something like this:

def res_lift(lambda_function: Callable[[], T]) -> Result[T, Exception]:
    try:
        return Result.from_value(lambda_function())
    except Exception as e:
        return Result.from_failure(e)

So that I can do something like res_lift(lambda: something_that_might_error()) and easily get a ResultE out. This would kind of be like Maybe's .from_optional method (https://returns.readthedocs.io/en/latest/pages/maybe.html#maybe-container), except it would be for ResultE.

I'm not totally sure it's feasible to implement this in a way that's general for all Result Failure types (I recognize that Exception isn't the only Failure type that people use), but if there's interest, I'd be happy to try and put together a PR for this or collaborate however would be useful!

Lingua principale
Python
Stelle
4.4k
Fork
154
Merge medio
3h 5m
PR unite (30g)
22

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dry-python/returns

Tutte le issue di dry-python/returns

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.