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

Casting NamedTuple with __call__ to Callable #9858

Open
b-x opened this issue Dec 30, 2020 · 2 comments
Open

Casting NamedTuple with __call__ to Callable #9858

b-x opened this issue Dec 30, 2020 · 2 comments
Labels
bug mypy got something wrong topic-named-tuple

Comments

@b-x
Copy link

b-x commented Dec 30, 2020

I think this should be valid:

from typing import Callable, NamedTuple

class Foo(NamedTuple):
    x: int

    def __call__(self) -> int:
        return self.x

foo: Callable[[], int] = Foo(42)

but mypy fails with:
error: Incompatible types in assignment (expression has type "Foo", variable has type "Callable[[], int]")

@b-x b-x added the bug mypy got something wrong label Dec 30, 2020
@aryansingla
Copy link

I want to contribute in it.
I will resolve this .

@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 1, 2022

Seems like it might be a problem that's specific to NamedTuples; mypy is happy with this code:

from typing import Callable

class Foo:
    def __call__(self) -> int: ...

foo: Callable[[], int] = Foo()

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-named-tuple
Projects
None yet
Development

No branches or pull requests

3 participants