Skip to content

Callback protocol with other attributes #10976

@erictraut

Description

@erictraut

I'm not sure if this is a mypy bug or intended behavior. I'm looking for advice.

PEP 544 introduced the concept of a callback protocol. In particular, it says:

[Callback protocols] can be defined as protocols with a call member

It is not clear to me whether a protocol that defines members other than __call__ is considered a callback protocol. PEP 544 says:

Callback protocols and Callable[...] types can be used interchangeably.

This could imply that a protocol class that includes attributes other than __call__ is not a callback protocol, but maybe I'm reading too much into it. I thought I remembered reading somewhere (perhaps on a typing-sig thread?) that if a protocol class included attributes other than __call__, it would not be considered a callback protocol, but I can't seem to find that thread.

A pyright user (@kennipj) recently filed this bug report. Currently, the behavior of pyright matches mypy in this case. I'm wondering if mypy's behavior is intended or whether it's a bug.

Here's another mypy bug that is related to this issue: #10403.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions