Skip to content

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

Closed

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

  1. added
    bug
    on Feb 9, 2023
  2. changed the title [-]error: Argument ... has incompatible type "function"; expected "Callable[[Any], None]"[/-] [+]Argument ... has incompatible type "function"; expected "Callable[[Any], None]"[/+] on Feb 9, 2023
  3. hauntsaninja commented on Feb 9, 2023

    @hauntsaninja
    Collaborator

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

  4. lobsterkatie commented on Feb 13, 2024

    @lobsterkatie

    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?

  5. brianschubert commented on Dec 2, 2024

    @brianschubert
    Collaborator

    This appears to be fixed now that union types are inferred for ternary expressions (#17427)

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

    bugtopic-ternary-expression

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions