Giter Club home page Giter Club logo

stateless's People

Contributors

pentusha avatar suned avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

pentusha

stateless's Issues

Mypy inference fails with parallel and runtime

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.

Explicit annotations of Runtime can lead to problems with type inference

Consider this:

from stateless import Runtime

r: Runtime[str | bytes] = Runtime().use('hello!')

According to mypy this is OK, since the right hand side value is inferred to be Runtime[str | bytes] due to the annotation. This in turn means that mypy also says that this is ok:

from stateless import Depend


e: Depend[bytes, float]
r.run(e)

But this in fact leads to a MissingDependencyError because r can't provide instances of byte.

Ideally, Runtime should be defined such that Runtime.use('hello!') can't be assigned to a variable of type Runtime[str | bytes] in the first place.

Relax Hashable type bounds on effect ability types

Currently abilities must be subtypes of typing.Hashable. This is solely due to the fact that looking up abilities is cached using functools.cache.

This requirement can be relaxed to allow unhashable ability types by only using the cached lookup when the ability is actually hashable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.