diff --git a/returns/_internal/futures/_future_result.py b/returns/_internal/futures/_future_result.py index 36c81bb0d..7f4ab2f9d 100644 --- a/returns/_internal/futures/_future_result.py +++ b/returns/_internal/futures/_future_result.py @@ -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 @@ -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') diff --git a/returns/_internal/futures/_reader_future_result.py b/returns/_internal/futures/_reader_future_result.py index b9468d2be..2a163b0f4 100644 --- a/returns/_internal/futures/_reader_future_result.py +++ b/returns/_internal/futures/_reader_future_result.py @@ -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 @@ -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') diff --git a/returns/context/requires_context_future_result.py b/returns/context/requires_context_future_result.py index 76c6ae4ce..d82c47905 100644 --- a/returns/context/requires_context_future_result.py +++ b/returns/context/requires_context_future_result.py @@ -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, diff --git a/returns/context/requires_context_ioresult.py b/returns/context/requires_context_ioresult.py index c6fe4785f..8c40d1b56 100644 --- a/returns/context/requires_context_ioresult.py +++ b/returns/context/requires_context_ioresult.py @@ -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], ): """ diff --git a/returns/context/requires_context_result.py b/returns/context/requires_context_result.py index 867b540ce..e72222dc6 100644 --- a/returns/context/requires_context_result.py +++ b/returns/context/requires_context_result.py @@ -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], ): """ diff --git a/returns/future.py b/returns/future.py index cb7bf1f29..c292be2d5 100644 --- a/returns/future.py +++ b/returns/future.py @@ -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 @@ -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') @@ -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], ): """ diff --git a/returns/io.py b/returns/io.py index 510765e25..0a483f9bb 100644 --- a/returns/io.py +++ b/returns/io.py @@ -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 @@ -37,7 +36,7 @@ _FuncParams = ParamSpec('_FuncParams') # Result related: -_ErrorType = TypeVar('_ErrorType', covariant=True) +_ErrorType = TypeVar('_ErrorType', covariant=True, default=Exception) _NewErrorType = TypeVar('_NewErrorType') @@ -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, ): diff --git a/returns/result.py b/returns/result.py index 0e8b8c5c6..74340bf62 100644 --- a/returns/result.py +++ b/returns/result.py @@ -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 @@ -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') @@ -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, ): diff --git a/typesafety/test_interfaces/test_specific/test_result/test_resultbased_inheritance.yml b/typesafety/test_interfaces/test_specific/test_result/test_resultbased_inheritance.yml index fe8f40fd2..b4577d3ea 100644 --- a/typesafety/test_interfaces/test_specific/test_result/test_resultbased_inheritance.yml +++ b/typesafety/test_interfaces/test_specific/test_result/test_resultbased_inheritance.yml @@ -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 @@ -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] @@ -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]