Hacker News new | ask | show | jobs
by patrec 3140 days ago
It's not possible to infer that the result `return x == y` is a bool, because python has rich comparisons (e.g. if x an y are numpy arrays you'll get an array of the same shape (after broadcasting) back). So either pytype uses additional information, or it's sometimes just wrong.
1 comments

Technically true, since you'll need to check the return type of `__eq__()`. But the following code doesn't trigger any error using `mypy test.py --check-untyped-defs`.

  def foo():
    x = 1
    return x == 2


  def bar(x: bool):
    print(x)


  def baz(x: int):
    print(x)


  if __name__ == '__main__':
    bar(foo())
    baz(foo())