mypy icon indicating copy to clipboard operation
mypy copied to clipboard

`any` breaks the type checking of its argument

Open UniverseFly opened this issue 1 year ago • 2 comments

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

UniverseFly avatar Oct 10 '22 06:10 UniverseFly

Related to #11994 ?

tmke8 avatar Oct 10 '22 16:10 tmke8

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

UniverseFly avatar Jan 14 '23 21:01 UniverseFly