Title: Add bound Hashable for types for keys of type Mapping and values of type Set · Issue #9571 · python/typeshed · GitHub
Open Graph Title: Add bound Hashable for types for keys of type Mapping and values of type Set · Issue #9571 · python/typeshed
X Title: Add bound Hashable for types for keys of type Mapping and values of type Set · Issue #9571 · python/typeshed
Description: Problem Types used for keys in mappings and values in sets are too broad. How to reproduce d: [list, int] = {} # Tools that use typeshed see this code as valid. d[[1]] = 2 # TypeError: unhashable type: 'list' Solution Change type of keys...
Open Graph Description: Problem Types used for keys in mappings and values in sets are too broad. How to reproduce d: [list, int] = {} # Tools that use typeshed see this code as valid. d[[1]] = 2 # TypeError: unhashable t...
X Description: Problem Types used for keys in mappings and values in sets are too broad. How to reproduce d: [list, int] = {} # Tools that use typeshed see this code as valid. d[[1]] = 2 # TypeError: unhashable t...
Opengraph URL: https://github.com/python/typeshed/issues/9571
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add bound Hashable for types for keys of type Mapping and values of type Set","articleBody":"### Problem\r\n\r\nTypes used for keys in mappings and values in sets are too broad.\r\n\r\n### How to reproduce\r\n\r\n```python\r\nd: [list, int] = {} # Tools that use typeshed see this code as valid.\r\nd[[1]] = 2 # TypeError: unhashable type: 'list'\r\n```\r\n\r\n### Solution\r\n\r\nChange type of keys in mappings: `_KT = TypeVar(\"_KT\")` to `_KT = TypeVar(\"_KT\", bound=Hashable)` \r\n- [x] Added [PR](https://github.com/python/typeshed/pull/9570) with fixes to stdlib\r\n\r\nBut I still have questions about how to fix the types in set and frozenset.\r\n\r\n- For set, we [using](https://github.com/python/typeshed/blob/main/stdlib/builtins.pyi#L1072) `_T`, which is also used for values in the list. Can I change it to `_KT`? The requirements for the type of values in the set are the same as for the keys in the dictionary. I understand that it is a value, not a key, and the name can be confusing. Do you think of a better option?\r\n- For frozenset, we [using](https://github.com/python/typeshed/blob/main/stdlib/builtins.pyi#L1111) covariant `_T_co`, which is also used for values in the tuple. It's the same problem here. We need a new type that is covariant and bound to Hashable.\r\n\r\n- [ ] set\r\n- [ ] frozenset\r\n\r\nAnd once we figure out what to do with types in stdlib, I will be happy to add the same changes to third-party libraries.\r\n","author":{"url":"https://github.com/kruvasyan","@type":"Person","name":"kruvasyan"},"datePublished":"2023-01-20T15:43:40Z","url":"https://github.com/python/typeshed/issues/9571"}
| 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:7db52199-3fb0-0070-53b2-79df8a40c7c4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D75E:12476C:1C603C6:2563C8F:6B002BD4 |
| html-safe-nonce | 2f5f536d063cbad77d38145cd560fc901d102927d00f092efaaf827e473e278a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzVFOjEyNDc2QzoxQzYwM0M2OjI1NjNDOEY6NkIwMDJCRDQiLCJ2aXNpdG9yX2lkIjoiNjE5MDQ1MDUwODU3MDgzMTgyOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 281c9168553476769842402387f0d9b2db933f043dced5aa9ce698b12d911793 |
| hovercard-subject-tag | issue:1551070718 |
| 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/9571/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8fea055c8c9829ed52c8c6c32c2bdb29e284db9735e26834e467bebbeb01a1b0/python/typeshed/issues/9571 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8fea055c8c9829ed52c8c6c32c2bdb29e284db9735e26834e467bebbeb01a1b0/python/typeshed/issues/9571 |
| og:image:alt | Problem Types used for keys in mappings and values in sets are too broad. How to reproduce d: [list, int] = {} # Tools that use typeshed see this code as valid. d[[1]] = 2 # TypeError: unhashable t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kruvasyan |
| 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