Suggest using Protocol when user tries to use keyword args with Callable
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start by reproducing the two examples in sample_python.py and inspect how mypy handles Callable annotations and keyword arguments. Review the issue's proposed Protocol direction and establish expected behavior for both examples; done means the agreed behavior is implemented and covered by tests for these cases.
Written by the indexing model from the issue text.
Description
If I define a passed in function using the Callable syntax, mypy complains if I then call a keyword argument on that function. This is makes writing things like decorators problematic
Sample code:
from typing import Callable
def test_func(a, b, c=0, d=0):
# type: (int, int, int, int) -> int
return a + b + c + d
def check_func(method):
# type: (Callable[[int, int, int], int]) -> int
return method(1, 2, d=5)
print(check_func(test_func))
$ mypy sample_python.py
sample_python.py: note: In function "check_func":
sample_python.py:9: error: Unexpected keyword argument "d"
As an aside here, I the following function code also raises mypy errors:
from typing import Callable
def test_func(a, b, *, c, d):
# type: (int, int, int, int) -> int
return a + b + c + d
def check_func(method):
# type: (Callable[[int, int, int, int], int]) -> int
return method(1, 2, c=5, d=10)
print(check_func(test_func))
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 54
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.
More from python/mypy
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug topic-configuration topic-error-reporting
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
area/auth bug comp/agent P3 platform/discord type/security
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
NousResearch/hermes-agent#117848 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100