Skip to content

Classes with __call__ defined should be a subtype of Callable #797

Closed
@zhangwen0411

Description

@zhangwen0411
def apply(f: Callable[[int], int], x: int) -> int:
  return f(x)

class Add5(object):
  def __call__(self, x: int) -> int:
    return x + 5

apply(Add5(), 5)

This code snippet doesn't type check because Mypy doesn't treat Add5() as a Callable[[int], int]

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions