stateless
stateless copied to clipboard
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.