99from returns .primitives .monad import Monad , NewValueType , ValueType
1010from returns .primitives .types import MonadType
1111
12- ErrorType = TypeVar ('ErrorType ' )
12+ _ErrorType = TypeVar ('_ErrorType ' )
1313
1414
1515# That's the most ugly part.
1616# We need to express `Either` with two type parameters and
1717# Left and Right with just one parameter.
1818# And that's how we do it. Any other and more cleaner ways are appreciated.
19- class Either (Generic [ValueType , ErrorType ], metaclass = ABCMeta ):
19+ class Either (Generic [ValueType , _ErrorType ], metaclass = ABCMeta ):
2020 """
2121 Represents a calculation that may either fail or succeed.
2222
@@ -26,7 +26,7 @@ class Either(Generic[ValueType, ErrorType], metaclass=ABCMeta):
2626 and 'Left' (or its alias 'Failure').
2727 """
2828
29- _inner_value : Union [ValueType , ErrorType ]
29+ _inner_value : Union [ValueType , _ErrorType ]
3030
3131 @abstractmethod
3232 def unwrap (self ) -> ValueType : # pragma: no cover
@@ -40,33 +40,33 @@ def unwrap(self) -> ValueType: # pragma: no cover
4040
4141
4242@final
43- class Left (Either [Any , ErrorType ], Monad [ErrorType ]):
43+ class Left (Either [Any , _ErrorType ], Monad [_ErrorType ]):
4444 """
4545 Represents a calculation which has failed.
4646
4747 It should contain an error code or message.
4848 To help with readability you may alternatively use the alias 'Failure'.
4949 """
5050
51- def __init__ (self , inner_value : ErrorType ) -> None :
51+ def __init__ (self , inner_value : _ErrorType ) -> None :
5252 """
5353 Wraps the given value in the Container.
5454
5555 'value' is any arbitrary value of any type including functions.
5656 """
5757 object .__setattr__ (self , '_inner_value' , inner_value )
5858
59- def fmap (self , function ) -> 'Left[ErrorType ]' :
59+ def fmap (self , function ) -> 'Left[_ErrorType ]' :
6060 """Returns the 'Left' instance that was used to call the method."""
6161 return self
6262
63- def bind (self , function ) -> 'Left[ErrorType ]' :
63+ def bind (self , function ) -> 'Left[_ErrorType ]' :
6464 """Returns the 'Left' instance that was used to call the method."""
6565 return self
6666
6767 def efmap (
6868 self ,
69- function : Callable [[ErrorType ], NewValueType ],
69+ function : Callable [[_ErrorType ], NewValueType ],
7070 ) -> 'Right[NewValueType]' :
7171 """
7272 Applies function to the inner value.
@@ -78,7 +78,7 @@ def efmap(
7878 """
7979 return Right (function (self ._inner_value ))
8080
81- def ebind (self , function : Callable [[ErrorType ], MonadType ]) -> MonadType :
81+ def ebind (self , function : Callable [[_ErrorType ], MonadType ]) -> MonadType :
8282 """
8383 Applies 'function' to the result of a previous calculation.
8484
@@ -95,7 +95,7 @@ def unwrap(self) -> NoReturn:
9595 """Raises an exception, since it does not have a value inside."""
9696 raise UnwrapFailedError (self )
9797
98- def failure (self ) -> ErrorType :
98+ def failure (self ) -> _ErrorType :
9999 """Unwraps inner error value from failed monad."""
100100 return self ._inner_value
101101
0 commit comments