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

error message: move star prefix to Argument #13146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

reka
Copy link

@reka reka commented Jul 16, 2022

Move * or ** prefix from argument type to "Argument".

Example

Before:

Argument 1 to "g" has incompatible type "**Dict[str, object]"

After:

**Argument 1 to "g" has incompatible type "Dict[str, object]"

Description

This is the 1st step to fix #8874 :

Move * or ** prefix from argument type to "Argument".

Further possible steps:

  1. Include the kwargs variable name (if any) in the error message
test.py:6: error: **Argument 2 ("json_kwargs") to "dumps" has incompatible type "Dict[str, int]"; expected "bool"
  1. Include the expected argument's name
test.py:6: error: **Argument 2 to "dumps" has incompatible type "Dict[str, int]"; expected "bool" for "skipkeys"
  1. Squash all error messages related to the same argument into one error message.

  2. Add a note with possible fixes:

...: note: Consider using a TypedDict type or "Dict[str, Any]" for the ** argument

Test Plan

  • No new tests added.
  • Updated existing tests.

Move * or ** prefix from argument type to "Argument".

Example
------------

Before:

```
Argument 1 to "g" has incompatible type "**Dict[str, object]"
```

After:

```
**Argument 1 to "g" has incompatible type "Dict[str, object]"
```
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

vision (https://github.com/pytorch/vision)
- torchvision/datasets/utils.py:71: error: Argument 1 to "md5" has incompatible type "**Dict[str, bool]"; expected "Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]]"  [arg-type]
+ torchvision/datasets/utils.py:71: error: **Argument 1 to "md5" has incompatible type "Dict[str, bool]"; expected "Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]]"  [arg-type]

pyppeteer (https://github.com/pyppeteer/pyppeteer)
- pyppeteer/launcher.py:149: error: Argument 2 to "Popen" has incompatible type "**Dict[str, Optional[Any]]"; expected "int"
+ pyppeteer/launcher.py:149: error: **Argument 2 to "Popen" has incompatible type "Dict[str, Optional[Any]]"; expected "int"
- pyppeteer/launcher.py:149: error: Argument 2 to "Popen" has incompatible type "**Dict[str, Optional[Any]]"; expected "bool"
+ pyppeteer/launcher.py:149: error: **Argument 2 to "Popen" has incompatible type "Dict[str, Optional[Any]]"; expected "bool"
- pyppeteer/launcher.py:149: error: Argument 2 to "Popen" has incompatible type "**Dict[str, Optional[Any]]"; expected "str"
+ pyppeteer/launcher.py:149: error: **Argument 2 to "Popen" has incompatible type "Dict[str, Optional[Any]]"; expected "str"

discord.py (https://github.com/Rapptz/discord.py)
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "str"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "str"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Iterable[str]"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Iterable[str]"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "float"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "float"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[float]"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[float]"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "bool"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "bool"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[BasicAuth]"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[BasicAuth]"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[str]"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[str]"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[Mapping[str, str]]"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[Mapping[str, str]]"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Union[Mapping[Union[str, istr], str], CIMultiDict[str], CIMultiDictProxy[str], None]"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Union[Mapping[Union[str, istr], str], CIMultiDict[str], CIMultiDictProxy[str], None]"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Union[str, URL, None]"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Union[str, URL, None]"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Union[SSLContext, bool, Fingerprint, None]"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Union[SSLContext, bool, Fingerprint, None]"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[bool]"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[bool]"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[bytes]"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[bytes]"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[SSLContext]"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "Optional[SSLContext]"
- discord/http.py:376: error: Argument 2 to "ws_connect" of "ClientSession" has incompatible type "**Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "int"
+ discord/http.py:376: error: **Argument 2 to "ws_connect" of "ClientSession" has incompatible type "Dict[str, Union[Dict[str, str], float, BasicAuth, None, str]]"; expected "int"
- discord/client.py:666: error: Argument 2 to "from_client" of "DiscordWebSocket" has incompatible type "**Dict[str, Optional[int]]"; expected "bool"
+ discord/client.py:666: error: **Argument 2 to "from_client" of "DiscordWebSocket" has incompatible type "Dict[str, Optional[int]]"; expected "bool"
- discord/client.py:666: error: Argument 2 to "from_client" of "DiscordWebSocket" has incompatible type "**Dict[str, Optional[int]]"; expected "Optional[str]"
+ discord/client.py:666: error: **Argument 2 to "from_client" of "DiscordWebSocket" has incompatible type "Dict[str, Optional[int]]"; expected "Optional[str]"

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 16, 2022

Thanks for the PR! I think that the error message would be a little clearer like this:

Unpacked argument 1 to "g" has incompatible type "Dict[str, object]"

We can use this message for both *args and **kwargs. What do you think?

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

Successfully merging this pull request may close these issues.

Generate better error message for incompatible **kwargs
2 participants