On Sat, Sep 26, 2020 at 10:47 PM Sascha Schlemmer via Python-ideas
<[email protected]> wrote:
> ```
> def div(a: int, b: int) -> Result[float, ZeroDivisionError]:
>   try:
>       return Success(a / b)
>   except ZeroDivisionError as error:
>       return Failure(error)
> ```
>
> Now `div` does return a valid instance of `Maybe` (or `Result` if more a more 
> detailed failure case is wanted) which is either something like  
> `Some(3.1415) ` or `Nothing` (analogous to `None` ). The caller of the 
> function then has to deal with this and mypy will correctly warn if the user 
> fails to do so properly e.g.
>

This is strictly worse than exception handling, because you're just
forcing every level to do a try/except. It's otherwise identical. Very
very bad idea to inflict this on Python programmers. Please do not
write any code like this in any function that you expect anyone else
to use.

ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/YVREVFRCLGVJM5MTCQGHFJZYQ23JRMGF/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to