KEMBAR78
Functions can't be passed as callable protocol · Issue #5453 · python/mypy · GitHub
Skip to content

Functions can't be passed as callable protocol #5453

@srittau

Description

@srittau

This came up in python/typeshed#2379. Consider the following code:

from typing import Protocol

class Caller(Protocol):
    def __call__(self) -> None: ...

def call() -> None:
    pass

def func(caller: Caller) -> None:
    pass

func(call)

Currently, mypy 0.620 rejects this:

foo.py:12: error: Argument 1 to "func" has incompatible type "Callable[[], None]"; expected "Caller"

I believe that mypy should actually allow this, because call is actually an object that fulfills the protocol. This would also open up the opportunity to create callback signatures of any complexity (for example, default and keyword-only arguments) without the need for additional features for Callable.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions