autotyping does not seem to find if/else branches that do not explicitly return
Closed this issue · 2 comments
twoertwein commented
autotyping annotates the following function as returning bool
but it should be bool | None
(example from pandas/util/_test_decorators.py)
def _skip_if_no_mpl():
mod = safe_import("matplotlib")
if mod:
mod.use("Agg")
else:
return True
def _skip_if_not_us_locale():
lang, _ = locale.getlocale()
if lang != "en_US":
return True
jakkdl commented
I think this is bad style, and is disallowed by e.g. pylint's inconsistent-return-statements
and pyanalyze's missing_return
.
It would also be quite complicated to try to infer all possible program flows through a function.
JelleZijlstra commented
I am going to document this as a known limitation. I don't want to add the logic to implement this properly to autotyping. In the general case (e.g., an exhaustive match statement over an enum) it requires the capabilities of a full type checker.