Open jesboat opened 5 years ago
I've encountered another instance of this:
from typing import List
# Always either returns int or throws Exception
def first_greater_than_ten(x: List[int]) -> int:
for i in x:
if i > 10:
return i
else:
raise Exception('None of the input numbers were greater than 10.')
Pyre complains that this function can return None (implicitly by reaching the end of the function definition with no return), when in fact it cannot:
test.py:9:8 Incompatible return type [7]: Expected `int` but got implicit return value of `None`.
If a variable is assigned in a for loop's body and its else clause, then it should be treated as defined at the loop's end. For example, this code is safe
but is rejected by Pyre with
The code which inspired this looked something like