dry-python / dry-python/returns

Consider adding decorators to work with generators

Aperta
#589 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement help wanted
Lingua principale
Python
Stelle
4.4k
Fork
155
Merge medio
2h 27m
PR unite (30g)
22

Descrizione

After think a lot about #355 it will be great to provide the same mechanisms we have to "normal" functions to generators!
It is not uncommon to see generators in many Python code, we use it when reading a file, iterating over Query objects and so on!

Today is impossible to work with generators using our current set of decorators like `@safe`:
```python
>>> from typing import Generator
>>> from returns.result import safe
>>>
>>> def numbers() -> Generator[int, None, None]:
... for x in range(2):
... yield x
...
>>> for number in numbers():
... print(number)
...
0
1
>>> for number in safe(numbers)():
... print(number)
...
Traceback (most recent call last):
File "", line 1, in
TypeError: '_Success' object is not iterable
```

Expected behavior:
```python
>>> from returns.result import safe_iter
>>>
>>> for number in safe_iter(numbers)():
... print(number)
...

```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.