mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Argument ... has incompatible type "function"; expected "Callable[[Any], None]"

Open Phlogistique opened this issue 2 years ago • 2 comments

Very similar to https://github.com/python/mypy/issues/1983 but still happens with mypy 1.0

Bug Report

To Reproduce

from typing import Callable, Any
from random import randrange
def test(x: Callable[[Any], None]): pass
def a(*y: Any) -> None: pass
def b(y: str) -> None: pass
test(a if randrange(2) else b)

https://mypy-play.net/?mypy=master&python=3.11&gist=a5b887f28bebad92989797587f29a123

Expected Behavior

The code type checks successfully.

Actual Behavior

main.py:6: error: Argument 1 to "test" has incompatible type "function"; expected "Callable[[Any], None]"  [arg-type]

Your Environment

  • Mypy version used: tested with 0.790, 1.0.0, and master
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: tested with 3.7 and 3.11

Phlogistique avatar Feb 09 '23 14:02 Phlogistique

Thanks, this is basically a duplicate of one half of #10740 (aka joins of callables could be more advanced)

hauntsaninja avatar Feb 09 '23 20:02 hauntsaninja

I'm running into the same error with Callable[..., str | None] - both options return str | None but have a different number of inputs. I'm on Python 3.11.6 and mypy 1.8.0.

Any progress on fixing this?

lobsterkatie avatar Feb 13 '24 04:02 lobsterkatie