Skip to content

Casting NamedTuple with __call__ to Callable #9858

Open
@b-x

Description

@b-x

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]")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions