to my knowledge no existing linter or type checker is able to detect mistakes like this. for example:
def get_values() -> list[int]:
return [i for i in range(3)]
values = get_values()
assert 4 not in values # passes
assert 1 in values # passes
but if get_values is updated to return a Generator instead of a list, it can unintentionally break existing usages:
from typing import Generator
def get_values() -> Generator[int]:
return (i for i in range(3))
values = get_values()
assert 4 not in values # passes
assert 1 in values # fails because the generator has no more values to iterate
i've encountered issues like this several times, so it would be nice if ty had a rule for it.
to my knowledge no existing linter or type checker is able to detect mistakes like this. for example:
but if
get_valuesis updated to return aGeneratorinstead of alist, it can unintentionally break existing usages:i've encountered issues like this several times, so it would be nice if ty had a rule for it.