2 ms·
> Mypy flags this problem through static analysis. The problem is that there's not really such a thing as static analysis in python. For example, if I wrap it
by lukeschlather 8y ago
> Mypy flags this problem through static analysis.
The problem is that there's not really such a thing as static analysis in python. For example, if I wrap it in a function like this, mypy doesn't complain at all.
def blah():
ages = {}
ages['John']: 42
print(ages['John'])
return ages
- goodside 8y agoMypy intentionally does not check annotations inside untyped `def` statements. This is a feature meant to make it easier to gradually introduce types in code that wasn't intended to be typechecked. If you call mypy with the flag `--check-untyped-defs` or just annotate the function with anything at all, you will see mypy checks the inside of the function: from typing import Any def blah() -> Any: ... I'm not sure what you mean by "there's not really such a thing as static analysis" in Python -- that's exactly what Mypy does.
- lukeschlather 8y agoCool, I knew I had to be missing something. You're right of course.