Title: Argument 2 to pop of MutableMapping has incompatible type · Issue #10152 · python/mypy · GitHub
Open Graph Title: Argument 2 to pop of MutableMapping has incompatible type · Issue #10152 · python/mypy
X Title: Argument 2 to pop of MutableMapping has incompatible type · Issue #10152 · python/mypy
Description: Bug Report Using MutableMapping.pop(key, default) inconsistently results in an error for the type of the default argument. To Reproduce import typing as t T = t.TypeVar('T') V = t.TypeVar('V') def test(key: T, value: V): values: t.Dict[T...
Open Graph Description: Bug Report Using MutableMapping.pop(key, default) inconsistently results in an error for the type of the default argument. To Reproduce import typing as t T = t.TypeVar('T') V = t.TypeVar('V') def ...
X Description: Bug Report Using MutableMapping.pop(key, default) inconsistently results in an error for the type of the default argument. To Reproduce import typing as t T = t.TypeVar('T') V = t.TypeVar(&...
Opengraph URL: https://github.com/python/mypy/issues/10152
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Argument 2 to pop of MutableMapping has incompatible type","articleBody":"\u003c!--\r\n If you're new to mypy and you're not sure whether what you're experiencing is a mypy bug, please see the \"Question and Help\" form\r\n instead.\r\n-->\r\n\r\n**Bug Report**\r\n\r\n\u003c!--\r\nNote: If the problem you are reporting is about a specific library function, then the typeshed tracker is better suited\r\nfor this report: https://github.com/python/typeshed/issues\r\n-->\r\n\r\nUsing `MutableMapping.pop(key, default)` inconsistently results in an error for the type of the `default` argument.\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nimport typing as t\r\nT = t.TypeVar('T')\r\nV = t.TypeVar('V')\r\ndef test(key: T, value: V):\r\n values: t.Dict[T, V] = {}\r\n print(values.pop(key, None)) # ok\r\n values.pop(key, value) # ok\r\n values.pop(key, None) # error: Argument 2 to \"pop\" of \"MutableMapping\" has incompatible type \"None\"; expected \"V\"\r\n values.pop(key, 42) # error: Argument 2 to \"pop\" of \"MutableMapping\" has incompatible type \"int\"; expected \"V\"\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nI expect no errors when checking the above code with Mypy. The definition of `MutableMapping.pop()` allows using a different type for the `default` argument value (in which case a union of the map's value type and the default argument's type is returned).\r\n\r\n```python\r\nclass MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):\r\n # ....\r\n @overload\r\n def pop(self, key: _KT, default: Union[_VT, _T] = ...) -> Union[_VT, _T]: ...\r\n```\r\n\r\nWhat is curious is that the line with `print()` does not result in an error, even though the `.pop()` call is the same as two lines below.\r\n\r\n**Your Environment**\r\n\r\n\u003c!-- Include as many relevant details about the environment you experienced the bug in -->\r\n\r\n- Mypy version used: 0.782, 0.812\r\n- Mypy command-line flags: N/a\r\n- Mypy configuration options from `mypy.ini` (and other config files): N/a\r\n- Python version used: CPython 3.7.3\r\n- Operating system and version: WSL Debian 10\r\n\r\n\u003c!--\r\nYou can freely edit this text, please remove all the lines\r\nyou believe are unnecessary.\r\n-->\r\n","author":{"url":"https://github.com/NiklasRosenstein","@type":"Person","name":"NiklasRosenstein"},"datePublished":"2021-02-28T12:36:43Z","url":"https://github.com/python/mypy/issues/10152"}
| 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:26203b17-4929-d003-f802-90b19b7e9003 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B5AE:07D0:1517E44:1BCF05C:6B001C26 |
| html-safe-nonce | bf71931e779d96fab167f2429aa8df955e9cfbe1c9b41822ab36dc5cf997e47d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNUFFOjA3RDA6MTUxN0U0NDoxQkNGMDVDOjZCMDAxQzI2IiwidmlzaXRvcl9pZCI6IjY1MDQ0NzkwMTgxMDI4MjM5NzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0a011a4060748636e8d45d329cdc334ef03f12464c279b1662438e093d8b46aa |
| hovercard-subject-tag | issue:818196885 |
| 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/10152/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8419470534dadc8cac338a89eb222015207a4b320e21627b074669bffc0a9315/python/mypy/issues/10152 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8419470534dadc8cac338a89eb222015207a4b320e21627b074669bffc0a9315/python/mypy/issues/10152 |
| og:image:alt | Bug Report Using MutableMapping.pop(key, default) inconsistently results in an error for the type of the default argument. To Reproduce import typing as t T = t.TypeVar('T') V = t.TypeVar('V') def ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | NiklasRosenstein |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width