You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working on -strict-optional mode in mypy, I noticed patterns like this many times:
deffunc(x: Optional[X]) ->Optional[Y]:
ifxisNone:
returnNone# do some stuff with 'x'
The most recent example appeared in python/mypy#3295. I could imagine this pattern (monadic behaviour) is quite common. If one uses "error as value" (i.e. passing None instead of using an exception), then the above pattern is necessary for "piping". Maybe we could provide a decorator that will automatically add such behaviour to a function, schematically:
While working on
-strict-optional
mode in mypy, I noticed patterns like this many times:The most recent example appeared in python/mypy#3295. I could imagine this pattern (monadic behaviour) is quite common. If one uses "error as value" (i.e. passing
None
instead of using an exception), then the above pattern is necessary for "piping". Maybe we could provide a decorator that will automatically add such behaviour to a function, schematically:The decorator is very simple, but the thing it does looks very common.
The text was updated successfully, but these errors were encountered: