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
"multiple values for keyword argument" with star expansion #6799
Updated priority to normal since this is a clear bug and we'd be happy to accept a PR that fixes this (at least if the fix is clean enough).
Reacted by Théo Matussière, Konstantin vz'One Enchant, Tim Martin, Romain Yon, Josh Temple, Igor Nehoroshev, Nick Sweeting, Denis Sidorenko, leska-j, Akihiro Nitta and 2 more
The above code is syntactically correct and runs fine, but mypy produces this on the super() line:
c:\Users\tim\code\blog-py\generator\foo.py:11: error: "__init__" of "Foo" gets multiple values for keyword argument "b"
For now, I will unfortunately # type: ignore this line in my code.
Reacted by Tea Geckle, Andreas Wachowski, jon-sch, Marius Helf, Augustin Prolongeau, Jonathan Lin, Matthew Arnold, Josh Temple, Nick Sweeting, dsbowen and 13 more
Since in your version above it would be possible to have multiple arguments for b passed to Foo. Unfortunately though, this re-writing still produces the same error.
Reacted by Roberto Cipollone and Jinwook Jeong (Edgar)
As an additional example, quite common when some of the parameters are loaded from some external source and then you need to supply the rest of the parameters explicitly:
class MyClass:
def __init__(self, param1: str, param2: str, param3: str):
self.param1 = param1
self.param2 = param2
data = {"param1": "value1", "param2": "value2"} # coming from some external source
result = MyClass(**data, param3="value3")
would give
error: "MyClass" gets multiple values for keyword argument "param3"
Reacted by myartsev, ccma14, Steffen, Solomon, joshv-marcrest, dylan-shipwell, Anton Bakker and Marie Payne
Edit: Just noticed the interesting output: argument types "tuple[Any, ...]", "str" as if the *args argument doesn't get flattened. I'm not sure whether that's just a peculiarity of mypy's output or a possible hint to what's going on internally.
Activity
ilevkivskyi commentedon May 8, 2019
Oh, it looks like one more place where we need to special-case union types.
ilevkivskyi commentedon May 8, 2019
I think this is a pretty rare situation, so I set priority to low.
JukkaL commentedon May 9, 2019
Updated priority to normal since this is a clear bug and we'd be happy to accept a PR that fixes this (at least if the fix is clean enough).
t-mart commentedon Nov 5, 2019
To add to the severity, consider this ubiquitous use case of initializing a constructor with custom keyword arguments:
The above code is syntactically correct and runs fine, but mypy produces this on the
super()line:For now, I will unfortunately
# type: ignorethis line in my code.rmorshea commentedon Apr 12, 2020
@t-mart technically I think it would be more correct to have
Bar's init be:Since in your version above it would be possible to have multiple arguments for
bpassed toFoo. Unfortunately though, this re-writing still produces the same error.alexey-tereshenkov-oxb commentedon Nov 27, 2020
As an additional example, quite common when some of the parameters are loaded from some external source and then you need to supply the rest of the parameters explicitly:
would give
hauntsaninja commentedon Nov 27, 2020
@alexey-tereshenkov-oxb your example passes on mypy master :-)
alexey-tereshenkov-oxb commentedon Nov 27, 2020
Thanks for pinging :) I am on
mypy 0.790DeepSpace2 commentedon Dec 3, 2023
I think this bug is still alive, even without using
Union.CyberTailor commentedon Jan 9, 2024
srittau commentedon Nov 17, 2025
A variant of this happens with overloads (see python/typeshed#15039):
When commenting out the overloads, this results in:
(
mypy 1.18.2 (compiled: yes))Edit: Just noticed the interesting output:
argument types "tuple[Any, ...]", "str"as if the*argsargument doesn't get flattened. I'm not sure whether that's just a peculiarity of mypy's output or a possible hint to what's going on internally.