Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valid combinations of *args and **kwargs with dataclasses give spurious "multiple values" errors #7657

Closed
cbowdon opened this issue Oct 8, 2019 · 1 comment

Comments

@cbowdon
Copy link

cbowdon commented Oct 8, 2019

  • Are you reporting a bug, or opening a feature request?
    Bug

  • Please insert below the code you are checking with mypy

from dataclasses import dataclass, asdict, astuple

@dataclass
class A:
    x: int = 0
    y: int = 0

@dataclass
class B(A):
    z: int = 0

a = A(1, 1)

# tuple unpacking -- fails
b = B(*astuple(a), z=1)  # error: "B" gets multiple values for keyword argument "z"
assert b == B(x=1, y=1, z=1)

# tuple unpacking -- fails
b = B(*astuple(a), 1)  # Too many arguments for "B"
assert b == B(x=1, y=1, z=1)

# dict unpacking -- succeeds
b = B(z=1, **asdict(a))
assert b == B(x=1, y=1, z=1)

# dict unpacking -- fails
b = B(**asdict(a), z=1)  # "B" gets multiple values for keyword argument "z"
assert b == B(x=1, y=1, z=1)
  • What is the actual behavior/output?
mypy example.py
example.py:16: error: "B" gets multiple values for keyword argument "z"
example.py:20: error: Too many arguments for "B"
example.py:28: error: "B" gets multiple values for keyword argument "z"
Found 3 errors in 1 file (checked 1 source file)

But python3 example.py succeeds with no errors.

  • What is the behavior/output you expect?

Ideally this should typecheck successfully. At least the error message should be more accurate.

  • What are the versions of mypy and Python you are using?
  • mypy 0.730
  • Python 3.7.3

Same results with: mypy 0.740+dev.beec11a28fd835acb1e4ee8b2bf14d969c4e5922

  • What are the mypy flags you are using? (For example --strict-optional)
    None
@ilevkivskyi
Copy link
Member

I think this is essentially a duplicate of #5152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants