-
-
Notifications
You must be signed in to change notification settings - Fork 130
We have a problem with @pipeline and unwrap() #90
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
Comments
It all translates to
inside |
When used as
So, we can forbid to use |
Some code samples: if fullname == 'returns.pipeline.pipeline':
def _analyze(function_ctx: FunctionContext):
from mypy.subtypes import check_type_parameter
from mypy.nodes import COVARIANT
print(
function_ctx.default_return_type.arg_types[0],
function_ctx.default_return_type.ret_type,
function_ctx.default_return_type.ret_type.type.module_name,
function_ctx.default_return_type.ret_type.type.name(),
)
print(
'direct',
check_type_parameter(
function_ctx.default_return_type.arg_types[0],
function_ctx.default_return_type.ret_type,
COVARIANT,
)
)
# function_ctx.api.errors.report(1, 1, 'Test error')
return function_ctx.default_return_type
return _analyze |
I am still playing around with from typing import TypeVar, Iterable, Generator, Iterator, Any
from returns.result import Result, Success, Failure
T = TypeVar('T', bound=Result)
V = TypeVar('V')
E = TypeVar('E')
def unwrap(monad: Result) -> Iterator[int]:
yield monad.unwrap()
def example(number: int) -> Generator[Result[int, Exception], int, None]:
a = yield Success(1)
b = yield Success(2)
# yield Failure('a')
# reveal_type(a)
print('a', a)
print('b', b)
# yield a
yield Success(a + b + number)
gen = example(2)
monad = gen.send(None) # type: ignore
print('send None', monad)
monad = gen.send(monad.unwrap())
print('send 1', monad)
monad = gen.send(monad.unwrap())
print('send 2', monad) This code does not produce any type errors in the user's space. Try to uncomment to play around:
|
Output:
And:
|
The thing is we cannot change the type of monads inside the pipeline: def example(number: int) -> Generator[Result[int, Exception], int, None]:
a = yield Success(1)
b = yield Success('2')
yield Success(a + int(b) + number) Output:
This is 100% required. Since without allowing different |
Now I will go for new |
Solutions:
|
There's literally nothing I can do about it.
|
Here's the deal:
Tree looks like so:
|
This works correctly with from returns import Result, Success, Failure, pipeline
@pipeline
def call(a: str) -> Result[int, str]:
Failure('a').unwrap()
return Failure(str).unwrap()
call('a') Call:
|
But still fails on: from typing import Union
from returns import Result, Success, Failure, pipeline
x: Result[bool, bool]
@pipeline
def call(a: str) -> Result[int, str]:
x.unwrap()
return Failure(str).unwrap()
call('a') Output:
|
The same happens with |
Nice idea: https://github.com/gcanti/fp-ts-contrib/blob/c94199e82fbf5c840a3bd4fb31653207ad053626/src/Do.ts We can invest into creating a plugin that can pass |
I am pretty sure, that we will have to change how
@pipeline
works.This is also related to #89
The text was updated successfully, but these errors were encountered: