Callable vs Protocol with `self` argument
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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