python / python/mypy

Callable vs Protocol with `self` argument

Open
#21,599 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

mypy seems to be unwilling to bind self to a decorated method if the method's return type is declared as a Protocol with __call__, but is willing to do so if the return type is Callable. See the example below.

To Reproduce

https://mypy-play.net/?gist=2fb651ddee58d4176237eb3c3dfb7c1a

Expected Behavior

I expect no type errors in any of the examples provided.

Actual Behavior

The first example (with class A and Callable) is accepted. The second is not.

decorator_confusion.py:45: error: Too few arguments for "__call__" of "MyCallable"  [call-arg]

Your Environment

Tested on mypy 1.18.2 and 2.1.0. Python version 3.14.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked mypy-play reproduction and inspect decorator_confusion.py, especially line 45 and the contrasting examples using Callable and MyCallable. Reproduce the error, then trace how decorated methods bind self when the return type is a Protocol with call; done means both examples type-check without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.