1717 overload ,
1818)
1919
20- from typing_extensions import ParamSpec
20+ from typing_extensions import ParamSpec , TypeAlias
2121
2222from returns .interfaces .specific import io , ioresult
2323from returns .primitives .container import BaseContainer , container_equality
@@ -882,8 +882,8 @@ def lash(self, function):
882882# Aliases:
883883
884884
885- #: Alias for a popular case when ``IOResult`` has `` Exception`` as error type .
886- IOResultE = IOResult [_ValueType , Exception ]
885+ #: Deprecated alias for ``IOResult[_ValueType, Exception]`` .
886+ IOResultE : TypeAlias = IOResult [_ValueType , Exception ]
887887
888888
889889# impure_safe decorator:
@@ -894,7 +894,8 @@ def lash(self, function):
894894@overload
895895def impure_safe (
896896 function : Callable [_FuncParams , _NewValueType ],
897- ) -> Callable [_FuncParams , IOResultE [_NewValueType ]]:
897+ / ,
898+ ) -> Callable [_FuncParams , IOResult [_NewValueType , Exception ]]:
898899 """Decorator to convert exception-throwing for any kind of Exception."""
899900
900901
@@ -908,11 +909,13 @@ def impure_safe(
908909 """Decorator to convert exception-throwing just for a set of Exceptions."""
909910
910911
911- def impure_safe ( # type: ignore # noqa: WPS234, C901
912- function : Optional [Callable [_FuncParams , _NewValueType ]] = None ,
913- exceptions : Optional [Tuple [Type [_ExceptionType ], ...]] = None ,
912+ def impure_safe ( # noqa: WPS234, C901
913+ exceptions : Union [
914+ Callable [_FuncParams , _NewValueType ],
915+ Tuple [Type [_ExceptionType ], ...],
916+ ],
914917) -> Union [
915- Callable [_FuncParams , IOResultE [_NewValueType ]],
918+ Callable [_FuncParams , IOResult [_NewValueType , Exception ]],
916919 Callable [
917920 [Callable [_FuncParams , _NewValueType ]],
918921 Callable [_FuncParams , IOResult [_NewValueType , _ExceptionType ]],
@@ -961,19 +964,22 @@ def impure_safe( # type: ignore # noqa: WPS234, C901
961964 """
962965 def factory (
963966 inner_function : Callable [_FuncParams , _NewValueType ],
964- inner_exceptions : Tuple [Type [Exception ], ...],
965- ) -> Callable [_FuncParams , IOResultE [_NewValueType ]]:
967+ inner_exceptions : Tuple [Type [_ExceptionType ], ...],
968+ ) -> Callable [_FuncParams , IOResult [_NewValueType , _ExceptionType ]]:
966969 @wraps (inner_function )
967- def decorator (* args : _FuncParams .args , ** kwargs : _FuncParams .kwargs ):
970+ def decorator (
971+ * args : _FuncParams .args ,
972+ ** kwargs : _FuncParams .kwargs ,
973+ ) -> IOResult [_NewValueType , _ExceptionType ]:
968974 try :
969975 return IOSuccess (inner_function (* args , ** kwargs ))
970976 except inner_exceptions as exc :
971977 return IOFailure (exc )
972978 return decorator
973979
974- if callable ( function ):
975- return factory (function , exceptions or ( Exception ,) )
976- if isinstance ( function , tuple ):
977- exceptions = function # type: ignore
978- function = None
979- return lambda function : factory ( function , exceptions ) # type: ignore
980+ if isinstance ( exceptions , tuple ):
981+ return lambda function : factory (function , exceptions )
982+ return factory (
983+ exceptions ,
984+ ( Exception ,), # type: ignore[arg-type]
985+ )
0 commit comments