mypy
mypy copied to clipboard
`any` breaks the type checking of its argument
Bug Report
Mypy cannot determine the type of the declared field inside a protocol method.
To Reproduce
Invoke mypy on the following Python file
# bug.py
from typing import List
x: List[str] = []
any(filter(lambda x : x.startswith(''), x))
Mypy complains: Argument 1 to "filter" has incompatible type "Callable[[Any], Any]"; expected "Callable[[str], TypeGuard[object]]"
.
Expected Behavior
No such error.
My Environment
- Mypy version used: https://github.com/python/mypy@e3827a1b950f83332656ad9c51ca8eea06ea2234
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.10.4
- Operating system and version: Ubuntu 20.04.4
Related to #11994 ?
Related to #11994 ?
Yes. The error still occurs in the latest version:
- Gist URL: https://gist.github.com/38c09a9474b0e30819de806af7f9ee7e
- Playground URL: https://mypy-play.net/?mypy=latest&python=3.11&gist=38c09a9474b0e30819de806af7f9ee7e