Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Phlogistique opened this issue Feb 9, 2023 · 3 comments
Labels
bug mypy got something wrong topic-ternary-expression a if b else c

Comments

@Phlogistique
Copy link
Contributor

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
@Phlogistique Phlogistique added the bug mypy got something wrong label Feb 9, 2023
@Phlogistique Phlogistique changed the title error: Argument ... has incompatible type "function"; expected "Callable[[Any], None]" Argument ... has incompatible type "function"; expected "Callable[[Any], None]" Feb 9, 2023
@hauntsaninja
Copy link
Collaborator

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

@ichard26 ichard26 added the topic-ternary-expression a if b else c label Feb 16, 2023
@lobsterkatie
Copy link

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?

@brianschubert
Copy link
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
Labels
bug mypy got something wrong topic-ternary-expression a if b else c
Projects
None yet
Development

No branches or pull requests

5 participants