-
-
Notifications
You must be signed in to change notification settings - Fork 3k
"multiple values for keyword" when passing keyword arguments after forwarding **args #2582
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
Comments
@sixolet Is this something that your function checking code would fix? |
No, it doesn't handle call sites at all, only function subtyping. I think there's a good question as to whether to assume double-splatting in a **kwargs to a function should be considered to fulfill all of the required keyword arguments not otherwise fulfilled, or fulfill none of them. Either way this is the wrong error message 😝 , and it should either provide a similar message for both |
Having thought about it for a minute: I think my favorite argument is that it should fulfill no required keyword arguments, and both The code above would either want a
|
(And I'd be happy to take an hour or two and make it so) |
I'm not sure I agree. More tomorrow.
|
|
The issue is that mypy doesn't keep track of the individual key/value pairs in a dict -- in general that won't work (even though there are some examples where it might seem to be trivial). Therefore it has no insight into whether a particular call involving A particularly common use case is a wrapper function. E.g. maybe I have some shortcut for calling def err(*args: Any, **kwds: Any):
logging.error(*args, **kwds) This should definitely satisfy the requirements of |
Yeah, I guess making it so that you can never supply required arguments with Are we okay with your Finally, I have a weird related set of corner cases that we should decide how to handle: def foo(a, b, c, d): pass
lst = [1]
foo(0, *lst, c=2, d=3) # Interpreter is fine with this, but only as long as lst is exactly len 1
foo(0, *lst, c=2) # This can never be ok.
lst = [1, 2, 3]
foo(0, *lst) # This is again fine, but only as long as lst is exactly len 3 |
Yes, I think that's a case where the For the I could also see rejecting all these examples because there's always a list length that will make it invalid, but that's probably not going to make us any friends either. So we should probably just not check this aspect of such calls. |
Jumping in to add one potential use case, perhaps for a plugin. I just stumbled upon this today. The use case is the following:
Rough code: import uuid
from dataclasses import dataclass
from marshmallow import Schema, fields
@dataclass
class Contact:
id: uuid.UUID
firstname: str
class ContactCreate(Schema):
firstname = fields.Str(required=True)
params = ContactCreate().load({'firstname': 'Louis'})
contact = Contact(**params, id=uuid.uuid4()) This gives:
I totally agree with @gvanrossum's rationale above. Nonetheless, do you think this would a good use case for a mypy plugin here? Could be interesting for validators packages such as |
This issue still persists, should be addressed ASAP |
Any updates on this? |
I think we actually just fixed this, see #9573 |
Any idea when this will be released in a new version? |
This is #2580 with the
--fast-parser
option.I wouldn't think the order matters. The Python interpreter does not have an issue with it.
The text was updated successfully, but these errors were encountered: