Skip to content

Spurious "Too many arguments" when unpacking empty dicts #9007

Description

@chkno

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions