Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update ErrorType with default=Exception #1892

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions returns/_internal/futures/_future_result.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar
from typing import TYPE_CHECKING, Any, Awaitable, Callable

from typing_extensions import TypeVar

from returns.io import IO, IOResult
from returns.primitives.hkt import Kind2, dekind
Expand All @@ -10,7 +12,7 @@

_ValueType = TypeVar('_ValueType', covariant=True)
_NewValueType = TypeVar('_NewValueType')
_ErrorType = TypeVar('_ErrorType', covariant=True)
_ErrorType = TypeVar('_ErrorType', covariant=True, default=Exception)
_NewErrorType = TypeVar('_NewErrorType')


Expand Down
6 changes: 4 additions & 2 deletions returns/_internal/futures/_reader_future_result.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar
from typing import TYPE_CHECKING, Awaitable, Callable

from typing_extensions import TypeVar

from returns.primitives.hkt import Kind3, dekind
from returns.result import Result, Success
Expand All @@ -8,7 +10,7 @@

_ValueType = TypeVar('_ValueType', covariant=True)
_NewValueType = TypeVar('_NewValueType')
_ErrorType = TypeVar('_ErrorType', covariant=True)
_ErrorType = TypeVar('_ErrorType', covariant=True, default=Exception)
_EnvType = TypeVar('_EnvType')


Expand Down
5 changes: 4 additions & 1 deletion returns/context/requires_context_future_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
class RequiresContextFutureResult( # type: ignore[type-var]
BaseContainer,
SupportsKind3[
'RequiresContextFutureResult', _ValueType, _ErrorType, _EnvType,
'RequiresContextFutureResult[Any, Any, Any]',
_ValueType,
_ErrorType,
_EnvType,
],
reader_future_result.ReaderFutureResultBasedN[
_ValueType, _ErrorType, _EnvType,
Expand Down
7 changes: 6 additions & 1 deletion returns/context/requires_context_ioresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
@final
class RequiresContextIOResult( # type: ignore[type-var]
BaseContainer,
SupportsKind3['RequiresContextIOResult', _ValueType, _ErrorType, _EnvType],
SupportsKind3[
'RequiresContextIOResult[Any, Any, Any]',
_ValueType,
_ErrorType,
_EnvType,
],
reader_ioresult.ReaderIOResultBasedN[_ValueType, _ErrorType, _EnvType],
):
"""
Expand Down
7 changes: 6 additions & 1 deletion returns/context/requires_context_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
@final
class RequiresContextResult( # type: ignore[type-var]
BaseContainer,
SupportsKind3['RequiresContextResult', _ValueType, _ErrorType, _EnvType],
SupportsKind3[
'RequiresContextResult[Any, Any, Any]',
_ValueType,
_ErrorType,
_EnvType,
],
reader_result.ReaderResultBasedN[_ValueType, _ErrorType, _EnvType],
):
"""
Expand Down
7 changes: 3 additions & 4 deletions returns/future.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
Generator,
Tuple,
Type,
TypeVar,
Union,
final,
overload,
)

from typing_extensions import ParamSpec, TypeAlias
from typing_extensions import ParamSpec, TypeAlias, TypeVar

from returns._internal.futures import _future, _future_result
from returns.interfaces.specific.future import FutureBased1
Expand All @@ -36,7 +35,7 @@
# Definitions:
_ValueType = TypeVar('_ValueType', covariant=True)
_NewValueType = TypeVar('_NewValueType')
_ErrorType = TypeVar('_ErrorType', covariant=True)
_ErrorType = TypeVar('_ErrorType', covariant=True, default=Exception)
_NewErrorType = TypeVar('_NewErrorType')

_FuncParams = ParamSpec('_FuncParams')
Expand Down Expand Up @@ -545,7 +544,7 @@ async def decorator(
@final
class FutureResult( # type: ignore[type-var]
BaseContainer,
SupportsKind2['FutureResult', _ValueType, _ErrorType],
SupportsKind2['FutureResult[Any, Any]', _ValueType, _ErrorType],
FutureResultBased2[_ValueType, _ErrorType],
):
"""
Expand Down
7 changes: 3 additions & 4 deletions returns/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
Optional,
Tuple,
Type,
TypeVar,
Union,
final,
overload,
)

from typing_extensions import ParamSpec, TypeAlias
from typing_extensions import ParamSpec, TypeAlias, TypeVar

from returns.interfaces.specific import io, ioresult
from returns.primitives.container import BaseContainer, container_equality
Expand All @@ -37,7 +36,7 @@
_FuncParams = ParamSpec('_FuncParams')

# Result related:
_ErrorType = TypeVar('_ErrorType', covariant=True)
_ErrorType = TypeVar('_ErrorType', covariant=True, default=Exception)
_NewErrorType = TypeVar('_NewErrorType')


Expand Down Expand Up @@ -279,7 +278,7 @@ def decorator(

class IOResult( # type: ignore[type-var]
BaseContainer,
SupportsKind2['IOResult', _ValueType, _ErrorType],
SupportsKind2['IOResult[Any, Any]', _ValueType, _ErrorType],
ioresult.IOResultBased2[_ValueType, _ErrorType],
metaclass=ABCMeta,
):
Expand Down
7 changes: 3 additions & 4 deletions returns/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
Optional,
Tuple,
Type,
TypeVar,
Union,
final,
overload,
)

from typing_extensions import Never, ParamSpec, TypeAlias
from typing_extensions import Never, ParamSpec, TypeAlias, TypeVar

from returns.interfaces.specific import result
from returns.primitives.container import BaseContainer, container_equality
Expand All @@ -27,7 +26,7 @@
# Definitions:
_ValueType = TypeVar('_ValueType', covariant=True)
_NewValueType = TypeVar('_NewValueType')
_ErrorType = TypeVar('_ErrorType', covariant=True)
_ErrorType = TypeVar('_ErrorType', covariant=True, default=Exception)
_NewErrorType = TypeVar('_NewErrorType')

_FirstType = TypeVar('_FirstType')
Expand All @@ -36,7 +35,7 @@

class Result( # type: ignore[type-var]
BaseContainer,
SupportsKind2['Result', _ValueType, _ErrorType],
SupportsKind2['Result[Any, Any]', _ValueType, _ErrorType],
result.ResultBased2[_ValueType, _ErrorType],
metaclass=ABCMeta,
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@
- case: result_inheritance_wrong
disable_cache: false
main: |
from typing import Callable, TypeVar
from typing import Callable
from typing_extensions import TypeVar
from returns.interfaces.specific.result import ResultBased2
from returns.primitives.hkt import SupportsKind2
from returns.result import Result
Expand All @@ -140,7 +141,7 @@
_NewValueType = TypeVar('_NewValueType')

# Result related:
_ErrorType = TypeVar('_ErrorType', covariant=True)
_ErrorType = TypeVar('_ErrorType', covariant=True, default=Exception)
_NewErrorType = TypeVar('_NewErrorType')

class MyClass( # type: ignore[type-var]
Expand All @@ -153,5 +154,5 @@
def failure(self) -> _ValueType:
...
out: |
main:17: error: Return type "_ErrorType" of "unwrap" incompatible with return type "_ValueType" in supertype "Unwrappable" [override]
main:20: error: Return type "_ValueType" of "failure" incompatible with return type "_ErrorType" in supertype "Unwrappable" [override]
main:18: error: Return type "_ErrorType" of "unwrap" incompatible with return type "_ValueType" in supertype "Unwrappable" [override]
main:21: error: Return type "_ValueType" of "failure" incompatible with return type "_ErrorType" in supertype "Unwrappable" [override]
Loading