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
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.
The text was updated successfully, but these errors were encountered:
### Description
Closes#5580
Previously, the type of empty dicts are inferred as `dict[<nothing>, <nothing>]`, which is not a subtype of `Mapping[str, Any]`, and this has caused a false-positive error saying `Keywords must be strings`. This PR fixes it by inferring the types of double-starred arguments with a context of `Mapping[str, Any]`.
Closes#4001 and closes#9007 (duplicate)
Do not check for "too many arguments" error when there are any double-starred arguments. This will lead to some false-negavites, see my comment here: #4001 (comment)
### Test Plan
Added a simple test `testPassingEmptyDictWithStars`. This single test can cover both of the issues above.
I also modified some existing tests that were added in #9573 and #6213.
mypy gives incorrect
Too many arguments
errors when unpacking empty dicts to zero-argument functions. Unpacking empty lists works fine.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.
The text was updated successfully, but these errors were encountered: