You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spurious "Too many arguments" when unpacking empty dicts #9007
mypy gives incorrect Too many arguments errors when unpacking empty dicts to zero-argument functions. Unpacking empty lists works fine.
from typing import Dict, List, NamedTuple
def f1():
pass
class C1(NamedTuple):
pass
d_zero: Dict[str,str] = {}
print((lambda: 42)(**{})) # error: Too many arguments
print((lambda: 42)(**d_zero)) # error: Too many arguments
print(f1(**{})) # error: Too many arguments for "f1"
print(f1(**d_zero)) # error: Too many arguments for "f1"
print(C1(**{})) # error: Too many arguments for "C1"
print(C1(**d_zero)) # error: Too many arguments for "C1"
# Empty lists work fine in recent versions:
l_zero: List[str] = []
print((lambda: 42)(*[]))
print((lambda: 42)(*l_zero))
print(f1(*[]))
print(f1(*l_zero))
print(C1(*[]))
print(C1(*l_zero))
I observe this problem all three versions of mypy that I tried: 0.701 0.761 0.770. The list examples also incorrectly give errors in 0.701, but this has been fixed in 0.761 and 0.770.
Activity
JukkaL commentedon Jun 19, 2020
Yeah, it seems that mypy should assume that the dictionary can be empty, for consistency with the list case.
NeilGirdhar commentedon Aug 19, 2020
This looks like #4001
Fix argument checking on empty dict with double stars (#9629)