stateless icon indicating copy to clipboard operation
stateless copied to clipboard

Mypy inference fails with parallel and runtime

Open suned opened this issue 8 months ago • 0 comments

Reproduce by:

from typing import NoReturn as Never

from stateless import Effect, Runtime, parallel, success
from stateless.parallel import Parallel, thread


def f() -> Effect[Never, ValueError, str]:
    return success("done")


task = reveal_type(thread(f)())
r: Runtime[Parallel] = Runtime()

r.run(parallel(task))  # Argument 1 to "parallel" has incompatible type "Task[NoReturn, ValueError, str]"; expected "Task[Parallel, ValueError, str]"

If you change the code to

from typing import NoReturn as Never

from stateless import Effect, Runtime, parallel, success
from stateless.parallel import Parallel, thread


def f() -> Effect[Never, ValueError, str]:
    return success("done")


task = reveal_type(thread(f)())
r: Runtime[Parallel] = Runtime()
effect = parallel(task)  # use an intermediate variable

r.run(effect)  # type error is gone

Type inference works.

Also interestingly, if you change the signature of f to () -> Effect[bytes, ValueError, str] or changes the type of r to Runtime[bytes | Parallel], inference also works.

suned avatar Nov 23 '23 14:11 suned