vickumar1981 / pyeffects

Handle side-effects in Python like a boss. Implements functional types for Either, Option, Try, and Future.
Other
30 stars 6 forks source link

Fixes type annotation of on_failure for Future. #25

Closed vickumar1981 closed 11 months ago

vickumar1981 commented 11 months ago

@sloboegen

Fixes the signature of the on_failure method for Future.

The callable that is passed should take in an exception and do nothing w/ it b/c on_failure is explicitly meant to handle side-effecting from an exception. i.e., i think the proper signature is Callable[[Exception], None] -> a function that takes in an exception and does nothing with it, just like your example that you provided in the docs.

def error():
  raise RuntimeError()
Future.run(error).on_failure(lambda _: print('ERROR!'))

The function being passed in takes an exception and returns nothing (None).

sloboegen commented 11 months ago

Yeah, you're absolutely right. No ideas why I've used Callable[[A], None] type...

vickumar1981 commented 11 months ago

@sloboegen Looks like this little change I made, breaks the case when the Future fails, but only for Python 3.11:

https://github.com/vickumar1981/pyeffects/actions/runs/6343401249/job/17231190521

Thanks for adding those tests. Would probably have never caught this otherwise! 👍