Unknown `DefaultNamedArg` raises type incompatibility errors
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
🐛 Bug Report
DefaultNamedArg may cause signature compatibility errors. Observed when a function has a default keyword argument in signature and is passed to be used as a function without that particular keyword argument.
To Reproduce
from typing import List, AnyStr
from glob import glob
import itertools as it
def expand_patterns(
pats: List[AnyStr],
sort=True
):
paths = it.chain(map(glob, pats))
# Argument 1 to "map" has incompatible type "Callable[[AnyStr, DefaultNamedArg(bool, 'recursive')], List[AnyStr]]"; expected "Callable[[AnyStr], List[AnyStr]]"
if sort:
paths = sorted(paths)
return paths
Expected Behavior
Not sure if this ought to happen, but I'd expect a function like foo(x: int, y='y') to be peacefully passable to a function expecting Callable[[int], Any].
Actual Behavior
# Argument 1 to "map" has incompatible type "Callable[[AnyStr, DefaultNamedArg(bool, 'recursive')], List[AnyStr]]"; expected "Callable[[AnyStr], List[AnyStr]]"
Your Environment
- Mypy version used: 0.782
- Mypy command-line flags: Default of VSCode
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.7.7
- Operating system and version: Windows 10, 2004
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 by reproducing the provided Python example involving glob, map, Callable compatibility, and DefaultNamedArg. Trace how mypy compares the callable signatures, then verify that a default keyword argument is handled according to the intended compatibility rule and that the reported incompatibility is resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100