Title: False positive with Dict passed to kwargs · Issue #6092 · python/mypy · GitHub
Open Graph Title: False positive with Dict passed to kwargs · Issue #6092 · python/mypy
X Title: False positive with Dict passed to kwargs · Issue #6092 · python/mypy
Description: When I run mypy on the following code: from typing import Dict, Mapping def f(*vargs: int, **kwargs: object) -> None: pass d = {} # type: Dict[str, object] f(**d) m = {} # type: Mapping[str, object] f(**m) It reports: 7: error: Argument ...
Open Graph Description: When I run mypy on the following code: from typing import Dict, Mapping def f(*vargs: int, **kwargs: object) -> None: pass d = {} # type: Dict[str, object] f(**d) m = {} # type: Mapping[str, object...
X Description: When I run mypy on the following code: from typing import Dict, Mapping def f(*vargs: int, **kwargs: object) -> None: pass d = {} # type: Dict[str, object] f(**d) m = {} # type: Mapping[str, obj...
Opengraph URL: https://github.com/python/mypy/issues/6092
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False positive with Dict passed to kwargs","articleBody":"When I run mypy on the following code:\r\n```py\r\nfrom typing import Dict, Mapping\r\n\r\ndef f(*vargs: int, **kwargs: object) -> None:\r\n\tpass\r\n\r\nd = {} # type: Dict[str, object]\r\nf(**d)\r\n\r\nm = {} # type: Mapping[str, object]\r\nf(**m)\r\n```\r\nIt reports:\r\n```\r\n7: error: Argument 1 to \"f\" has incompatible type \"**Dict[str, object]\"; expected \"int\"\r\n```\r\nLine 7 contains `f(**d)`.\r\n\r\nI don't understand why mypy expects `int` as the type of an argument passed using `**`: as far as I know, there is no way for a value passed using `**` to be captured by an argument declared with `*`. Even if the passed map contains a key named `vargs`, its value would still end up in `kwargs`.\r\n\r\nNote that arguments passed with `**` are not positional, so the error message stating \"Argument 1\" is either poorly worded or perhaps the result of the same problem that causes the false positive.\r\n\r\nWhat is confusing to me is that this false positive only occurs if I pass a `Dict`, not a `Mapping`. However, Python will create a new dictionary instance for `kwargs` in either case, so only the key and value types of the expression after `**` should matter, I think, not the mapping type.\r\n\r\nI'm using mypy 0.650 with Python 3.6.5.\r\n","author":{"url":"https://github.com/mthuurne","@type":"Person","name":"mthuurne"},"datePublished":"2018-12-20T05:38:03Z","url":"https://github.com/python/mypy/issues/6092"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d8a0b637-02f7-95f7-4ea0-244935d08374 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A0D0:12476C:1D51FC1:26A5366:6B002FFF |
| html-safe-nonce | 3e55bc8df12d82f8c25ab02419a8b7acacc9dee53f558caeaf6db51740cc6c9f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMEQwOjEyNDc2QzoxRDUxRkMxOjI2QTUzNjY6NkIwMDJGRkYiLCJ2aXNpdG9yX2lkIjoiNDkwOTA4MjY3MjYyNzcyNDI4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6634fda9f0110f394949148123416e1c3f016c64fcc189807217d6ad9e4df061 |
| hovercard-subject-tag | issue:392897456 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/6092/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5649144513622a1d918e1c1d9fa8ae872eb57a7dd868ff54075da6184ebc76ff/python/mypy/issues/6092 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5649144513622a1d918e1c1d9fa8ae872eb57a7dd868ff54075da6184ebc76ff/python/mypy/issues/6092 |
| og:image:alt | When I run mypy on the following code: from typing import Dict, Mapping def f(*vargs: int, **kwargs: object) -> None: pass d = {} # type: Dict[str, object] f(**d) m = {} # type: Mapping[str, object... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mthuurne |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width