Title: Mapping.values() return type is too narrow · Issue #4435 · python/typeshed · GitHub
Open Graph Title: Mapping.values() return type is too narrow · Issue #4435 · python/typeshed
X Title: Mapping.values() return type is too narrow · Issue #4435 · python/typeshed
Description: Currently, the type hint for Mapping.values() requires implementors of the Mapping interface to return a ValuesView: class Mapping(_Collection[_KT], Generic[_KT, _VT_co]): ... def values(self) -> ValuesView[_VT_co]: ... But ValuesView is...
Open Graph Description: Currently, the type hint for Mapping.values() requires implementors of the Mapping interface to return a ValuesView: class Mapping(_Collection[_KT], Generic[_KT, _VT_co]): ... def values(self) -> V...
X Description: Currently, the type hint for Mapping.values() requires implementors of the Mapping interface to return a ValuesView: class Mapping(_Collection[_KT], Generic[_KT, _VT_co]): ... def values(self) ->...
Opengraph URL: https://github.com/python/typeshed/issues/4435
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mapping.values() return type is too narrow","articleBody":"Currently, the type hint for `Mapping.values()` [requires implementors of the `Mapping` interface to return a `ValuesView`](https://github.com/python/typeshed/blob/f46fb7/stdlib/3/typing.pyi#L425):\r\n```python\r\nclass Mapping(_Collection[_KT], Generic[_KT, _VT_co]):\r\n ...\r\n def values(self) -> ValuesView[_VT_co]: ...\r\n```\r\n\r\nBut `ValuesView` is too narrow. For example, an ABC for a `BidirectionalMapping` interface which extends the `Mapping` interface should be able to declare that the `values()` method returns an `AbstractSet` (since the values of a bidirectional mapping actually make up a set), [as I need to do in my `bidict` library](https://github.com/jab/bidict/blob/master/bidict/_abc.py#L81). Note that an `AbstractSet` satisfies the contract of a `ValuesView`. But currently declaring this causes the mypy error, `Return type \"AbstractSet[VT]\" of \"values\" incompatible with return type \"ValuesView[VT]\" in supertype \"Mapping\"`.\r\n\r\n(Notice that the type hints for `Mapping.keys()` and `Mapping.items()` return `AbstractSet` rather than `KeysView` and `ItemsView`, respectively, because even `KeysView` and `ItemsView` would have been too narrow there. In other words, those type hints are abstract enough. Only the type hint for `values()` is not abstract enough.)\r\n\r\nIt looks like one way to fix this would be to declare that `Mapping.values()` must return a `Collection[VT]` rather than a `ValuesView[VT]`. Since `AbstractSet` is a subtype of `Collection`, then `BidirectionalMapping.values()` (and other implementors) could return an `AbstractSet[VT]` (or any other subtype) and still satisfy the contract for `Mapping.values()`.\r\n\r\nDoes that make sense, or would some other fix be better here?","author":{"url":"https://github.com/jab","@type":"Person","name":"jab"},"datePublished":"2020-08-10T22:50:47Z","url":"https://github.com/python/typeshed/issues/4435"}
| 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:170e9601-92d3-82e9-dfcf-33b65c5b05f2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CC5A:1CF166:2714D4B:3541E0F:6B0042CC |
| html-safe-nonce | 5ef0716bfafe1a567671ea02ca76021098cd16eb69f80d9ba44411387f71e76e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQzVBOjFDRjE2NjoyNzE0RDRCOjM1NDFFMEY6NkIwMDQyQ0MiLCJ2aXNpdG9yX2lkIjoiMjgyOTA1Nzk0OTkzNzE4OTU4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 238f8b35eb59d9400a69319befc779d9be1e4eafe47e0fac49d23682256c2210 |
| hovercard-subject-tag | issue:676462764 |
| 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/4435/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9b0ed38d7f4f8c5b347794d4b4cfda105252b2d380f4ae08eeab1933d529e1cf/python/typeshed/issues/4435 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9b0ed38d7f4f8c5b347794d4b4cfda105252b2d380f4ae08eeab1933d529e1cf/python/typeshed/issues/4435 |
| og:image:alt | Currently, the type hint for Mapping.values() requires implementors of the Mapping interface to return a ValuesView: class Mapping(_Collection[_KT], Generic[_KT, _VT_co]): ... def values(self) -> V... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jab |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width