The following minified example was originally found while making changes to my work's code base. I have the line x: List[str] = [] so I expect that mypy will enforce that, but in this example it seems it does not. If I want mypy to catch this, what should I do differently?
from typing import List
x: List[str] = []
y = ["world"]
z = ["hello"]
def go(boop):
return f"{boop}!", y
x = list(map(go, z))
print(x)
# output:
# [('hello!', ['world'])]
$ mypy mypy_lists.py
Success: no issues found in 1 source file
$ python3 mypy_lists.py
[('hello!', ['world'])]
EDIT:
For context, the , y part of the definition of go was a copy-paste error, and I expected to be protected against that by just the x: List[str] annotation, but maybe I have to update my internal model of mypy type checking, and just trust it less.
EDIT 2:
Given the accepted answer, the amount I can trust mypy with type hints seems to be directly related to the way mypy is configured. Not terribly surprising, but a good thing to remember.