Skip to content

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

Description

@Phlogistique

Very similar to #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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions