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

Add a method to get intermediate return values from flow

Aperta
#868 3 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
30/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
testing

Direzione di ricerca

Inizia individuando gli entry point esistenti di assert_flow e flow, quindi leggi la proof of concept di tracing Python che usa sys.setprofile e return events. Il lavoro è completato quando un metodo di test supportato può recuperare un risultato intermedio di flow e sono presenti test che coprono il valore previsto.

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

Descrizione

Hi!

It would be nice for testing to have a way to retrieve the intermediate result of a flow, in a way similar to how assert_flow() works but with the return value.

Example:

def do_stuff():
    return flow(0, func_1, bind(func_2))

def test_func_1():
    v = get_function_value(func_1, do_stuff)
    assert v == expected_value

In principle this can be done with sys.setprofile (in the trace function and for return events, arg contains the return value).

Proof of concept example:

def trace_func(function_to_search, frame, event, arg):
    if event == 'return' and frame.f_code.co_name == function_to_search.__name__:
        # modified exception to hold the return value under "value" attr
        raise DesiredValueFound(arg)

def get_function_value(function_to_search, my_flow):
    old_tracer = sys.gettrace()
    sys.setprofile(partial(trace_func, function_to_search))

    try:
         my_flow()
    except DesiredValueFound as e:
        return e.value
    finally:
        sys.settrace(old_tracer)

What do you think?

Thanks :)

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.