Better error message for incompatible unpacked **kwargs#8960
Conversation
| you need to ensure the types of dictionary members by providing either | ||
| a TypedDict or a variable with type Dict[str, Any]. | ||
|
|
||
| For example, the following function calls are valid: |
There was a problem hiding this comment.
Just a suggestion - maybe an example that shows some offending cases or invalid function calls would help drive the point home? (otherwise good job!)
| arg_type_str = '*' + arg_type_str | ||
| elif arg_kind == ARG_STAR2: | ||
| arg_type_str = '**' + arg_type_str | ||
| notes.append("Use TypedDict or Dict[str, Any] for unpacked **kwargs") |
There was a problem hiding this comment.
Hey! You will also have to modify the tests affected by this change :) Cheers!
- added note in outputs
91ecf39 to
9a4e59e
Compare
|
Any updates on this? Updated PR with respect to master |
|
I'm not sure adding this note is actually helpful. The root problem seems to be that the current error is just confusing -- it says (for example) argument has incompatible type "**Dict[str, float]"; expected "int" where it should explain that the dict's value type is not compatible with all of the function's argument type, or something like that. It is easy to come up with examples where the note is just wrong, e.g. |
|
The note is needed in cases where the Dict is untyped and inferred type becomes Even though types are correct, it fails. In cases where inferred dict type is not |
In this case we should do what Jukka suggested in his first bullet in #8874: "Generate a single error message instead of multiple ones."
I'm thinking there are several cases.
In the example you give, maybe the error should be (However, I don't know if all the information needed to format it that way is actually available.) |
hauntsaninja
left a comment
There was a problem hiding this comment.
Requesting changes as per gvanrossum's comment
|
Hi, any progress on this PR? |
|
Closing due to inactivity. |
Closes #8874
Added a note for unpacked **kwargs.
I believe there should be multiple error messages, to inform of all callable argument type mismatch.
Hence, I have added just a note.
Also, added in Common Issues.