suned / stateless Goto Github PK
View Code? Open in Web Editor NEWStatically typed, purely functional effects for Python.
License: MIT License
Statically typed, purely functional effects for Python.
License: MIT License
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.
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.