Title: The type of __default= in dict.pop and dict.get doesn't look right · Issue #10293 · python/typeshed · GitHub
Open Graph Title: The type of __default= in dict.pop and dict.get doesn't look right · Issue #10293 · python/typeshed
X Title: The type of __default= in dict.pop and dict.get doesn't look right · Issue #10293 · python/typeshed
Description: dict.pop is currently defined as typeshed/stdlib/builtins.pyi Lines 1086 to 1089 in 1851423 @overload def pop(self, __key: _KT) -> _VT: ... @overload def pop(self, __key: _KT, __default: _VT | _T) -> _VT | _T: ... Note the union with two...
Open Graph Description: dict.pop is currently defined as typeshed/stdlib/builtins.pyi Lines 1086 to 1089 in 1851423 @overload def pop(self, __key: _KT) -> _VT: ... @overload def pop(self, __key: _KT, __default: _VT | _T) ...
X Description: dict.pop is currently defined as typeshed/stdlib/builtins.pyi Lines 1086 to 1089 in 1851423 @overload def pop(self, __key: _KT) -> _VT: ... @overload def pop(self, __key: _KT, __default: _VT | _...
Opengraph URL: https://github.com/python/typeshed/issues/10293
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"The type of __default= in dict.pop and dict.get doesn't look right","articleBody":"`dict.pop` is currently defined as \r\n\r\nhttps://github.com/python/typeshed/blob/18514235198637fd2f9a7a92084a73d630da8f17/stdlib/builtins.pyi#L1086-L1089\r\n\r\nNote the union with two type parameters as a type of `__default=`. This type is ambiguous if `dict.pop` is called with a value of type `_VT`. For example, given\r\n\r\n```\r\nd: dict[str, str]\r\nd.pop(\"foo\")\r\n```\r\n\r\na type checker can choose any value for `_T`, since `str` is a subtype of `str | _T` regardless of what `_T` is. \r\n\r\nIt seems the union was introduced in 2fdcd2e9e8e51b138f03df8e0d96e88c4b280110, which unfortunately does not seem to give any reasoning for that. I think we should drop it and use `_T` instead in both `dict.pop` and `dict.get` (and similarly for `MutableMapping`), i.e.\r\n\r\n```\r\nclass dict(Generic[_KT, _VT]):\r\n # ...\r\n @overload\r\n def pop(self, __key: _KT, __default: _T) -> _T: ...\r\n```","author":{"url":"https://github.com/superbobry","@type":"Person","name":"superbobry"},"datePublished":"2023-06-09T19:28:20Z","url":"https://github.com/python/typeshed/issues/10293"}
| 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:25c899a5-d9e2-25ba-fb9d-5dffe00b05ea |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B3CC:1AC37C:13EC87:1AD934:6B001EDF |
| html-safe-nonce | 081b64ad7bfcc89d1b21dca62ca12b7c55bd6d3caf647c5e62fb88535d766ee4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0NDOjFBQzM3QzoxM0VDODc6MUFEOTM0OjZCMDAxRURGIiwidmlzaXRvcl9pZCI6IjgwNDMzOTY5Mzg3NzI1MjA2NzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ca21ccf381d5a529eba6eea192f5e03a16ba96a07fa5b17088210ae639d55217 |
| hovercard-subject-tag | issue:1750399232 |
| 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/typeshed/10293/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4f6632c618d1a13e699339a7bafc7549ce157a04a2707adda340d151eb16c003/python/typeshed/issues/10293 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4f6632c618d1a13e699339a7bafc7549ce157a04a2707adda340d151eb16c003/python/typeshed/issues/10293 |
| og:image:alt | dict.pop is currently defined as typeshed/stdlib/builtins.pyi Lines 1086 to 1089 in 1851423 @overload def pop(self, __key: _KT) -> _VT: ... @overload def pop(self, __key: _KT, __default: _VT | _T) ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | superbobry |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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