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... #1983

Closed
jstasiak opened this issue Aug 4, 2016 · 2 comments
Closed

Comments

@jstasiak
Copy link
Contributor

jstasiak commented Aug 4, 2016

I've looked for a similar report but couldn't find any - forgive me if there is one.

It seems to me that this code should pass type check:

from typing import Any, Callable


def fun() -> None:
    callbacks = [
        callback1,
        callback2,
    ]

    for c in callbacks:
        call(c, 1234)


def callback1(i: int) -> int:
    return i


def callback2(i: int) -> str:
    return 'hello'


def call(c: Callable[[int], Any], i: int) -> None:
    c(i)

mypy a284c48 doesn't like it:

test.py: note: In function "fun":
test.py:11: error: Argument 1 to "call" has incompatible type "function"; expected Callable[[int], Any]
@gnprice gnprice added the feature label Aug 4, 2016
@gnprice gnprice added this to the 0.4.x milestone Aug 4, 2016
@ddfisher
Copy link
Collaborator

ddfisher commented Aug 4, 2016

Thanks for the bug report! It looks to me like we're not computing the join of Callables correctly. This might be a quick fix -- I'll see if I can take a look in the next couple days!

@ddfisher ddfisher self-assigned this Aug 4, 2016
@rwbarton
Copy link
Contributor

rwbarton commented Aug 4, 2016

You can make this program typecheck by adding an annotation # type: List[Callable[[int], object]] to the list. It does seem like mypy should probably be able to work that out itself, though.

@gvanrossum gvanrossum removed this from the 0.4.x milestone Mar 29, 2017
JukkaL pushed a commit that referenced this issue Apr 3, 2017
Fixes #1983

Here I implement:

* join(Callable[[A1], R1]), Callable[[A2], R2]) == Callable[[meet(A1, A2)], join(R1, R2)]
* meet(Callable[[A1], R1]), Callable[[A2], R2]) == Callable[[join(A1, A2)], meet(R1, R2)]

plus special cases for Any, overloads, and callable type objects.

The meet and join are still not perfect, but I think this PR improves the situation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants