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
Misleading error when using a dict of keyword args #14073
When passing at least part of the function parameter as an ** expanded dictionary, if one or more of the parameters is missing, a misleading "incomaptible type" is shown, instead of "missing parameter".
See also stackoverflow for a way to get a better (but still not correct, since it lists all the parameters as missing) message
This report is a bit misleading since it might appear that in the example, the problem is that mypy understands that input_kwargs provides parameter b but not a and c, which in practice input_kwargs is seen as an opaque dict[str, bool].
main.py:6: error: Argument 1 to "f" has incompatible type "**Dict[str, str]"; expected "int" [arg-type]
main.py:6: error: Argument 1 to "f" has incompatible type "**Dict[str, str]"; expected "bool" [arg-type]
Now, as to what's "expected", maybe something like this?
main.py:6: error: Argument 1 to "f" has incompatible type "**Dict[str, str]"; expected named arguments "(foo: int, bar: bool)"
or maybe, if we want to nudge users towards TypedDict:
... or a TypedDict:
class ...(TypedDict):
foo: int
bar: bool
Activity
ikonst commentedon Jan 27, 2023
This report is a bit misleading since it might appear that in the example, the problem is that mypy understands that
input_kwargsprovides parameterbbut notaandc, which in practiceinput_kwargsis seen as an opaquedict[str, bool].A simpler case is:
Actual:
Now, as to what's "expected", maybe something like this?
or maybe, if we want to nudge users towards TypedDict:
Playground URL: https://mypy-play.net/?gist=3d6875bd1447fe1b1259c3455155bea5