Nothing_.__iter__ method not typed correctly?
Closed this issue · 1 comments
ssjw commented
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
:
def __iter__(self) -> Generator[TSource, TSource, TSource]:
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.