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.
Consider this:
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:But this in fact leads to a
MissingDependencyErrorbecausercan't provide instances ofbyte.Ideally,
Runtimeshould be defined such thatRuntime.use('hello!')can't be assigned to a variable of typeRuntime[str | bytes]in the first place.