The example from the tutorial does not type check with Pylance:
from expression import effect, Some, Nothing
@effect.option
def fn():
x = yield from Nothing # or a function returning Nothing
# -- The rest of the function will never be executed --
y = yield from Some(43)
return x + y
xs = fn()
assert xs is Nothing
Type checking fails at x = yield from Nothing -- Pylance thinks it is Unknown type. However, if I change the return type of Nothing_.__iter__ to be like the return type from Some:
Then x = yield from Nothing type checks to an Any. Which, given the type of Nothing seems correct. Though of course nothing will yield from Nothing because of the raise Nothing in __iter__.
However, I don't know if changing the return type to Generator has negative consequences in other contexts.
The example from the tutorial does not type check with Pylance:
Type checking fails at
x = yield from Nothing
-- Pylance thinks it is Unknown type. However, if I change the return type ofNothing_.__iter__
to be like the return type fromSome
:Then
x = yield from Nothing
type checks to anAny
. Which, given the type ofNothing
seems correct. Though of course nothing will yield fromNothing
because of theraise Nothing
in__iter__
.However, I don't know if changing the return type to
Generator
has negative consequences in other contexts.