Title: Disallow `Mapping` as argument type? · Issue #3576 · python/typeshed · GitHub
Open Graph Title: Disallow `Mapping` as argument type? · Issue #3576 · python/typeshed
X Title: Disallow `Mapping` as argument type? · Issue #3576 · python/typeshed
Description: This came up in #3569. See also the later comments in python/typing#11 for background. Mapping is not a protocol (as opposed to most other typing ABCs). This mean code like the following will not work: from typing import Iterator, Mappin...
Open Graph Description: This came up in #3569. See also the later comments in python/typing#11 for background. Mapping is not a protocol (as opposed to most other typing ABCs). This mean code like the following will not w...
X Description: This came up in #3569. See also the later comments in python/typing#11 for background. Mapping is not a protocol (as opposed to most other typing ABCs). This mean code like the following will not w...
Opengraph URL: https://github.com/python/typeshed/issues/3576
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Disallow `Mapping` as argument type?","articleBody":"This came up in #3569. See also the later comments in python/typing#11 for background. `Mapping` is not a protocol (as opposed to most other typing ABCs). This mean code like the following will not work:\r\n\r\n```python\r\nfrom typing import Iterator, Mapping\r\n\r\nclass MyMap:\r\n def __getitem__(self, key: str) -> int:\r\n return 0\r\n def __iter__(self) -> Iterator[str]:\r\n return iter([])\r\n def __len__(self) -> int:\r\n return 0\r\n def __contains__(self, key: object) -> bool:\r\n return False\r\n\r\ndef foo(x: Mapping[str, int]) -> None:\r\n pass\r\n\r\nfoo(MyMap()) # error: Argument 1 to \"foo\" has incompatible type \"MyMap\"; expected \"Mapping[str, int]\"\r\n```\r\n\r\nDeriving `MyMap` from `Mapping[str, int]` works, though. I suggest we don't allow new submissions to use `Mapping` as argument type and work towards removing existing uses. Instead they should use a custom protocol, which can also be narrower than `Mapping`.","author":{"url":"https://github.com/srittau","@type":"Person","name":"srittau"},"datePublished":"2020-01-05T16:10:36Z","url":"https://github.com/python/typeshed/issues/3576"}
| 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:23edd63f-4ec9-115e-22ab-9229ea66d66e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8652:D064:2205482:2E2E417:6B0023D0 |
| html-safe-nonce | fc7f4eb84bb64f1c0c333e8eeb8b835ab0cfee94f598186bda53360c180c0bf9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjUyOkQwNjQ6MjIwNTQ4MjoyRTJFNDE3OjZCMDAyM0QwIiwidmlzaXRvcl9pZCI6IjYwODUzODA1NzYxMjUxMzM3NzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8dfcfa7631da6c951d43baefe118797ac4a76e72b37126b95d880bef7ef7f588 |
| hovercard-subject-tag | issue:545436172 |
| 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/3576/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6dea56378e4cc627a59b8a6071fe67f571da06e908e6b667b16471b5b76ecf46/python/typeshed/issues/3576 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6dea56378e4cc627a59b8a6071fe67f571da06e908e6b667b16471b5b76ecf46/python/typeshed/issues/3576 |
| og:image:alt | This came up in #3569. See also the later comments in python/typing#11 for background. Mapping is not a protocol (as opposed to most other typing ABCs). This mean code like the following will not w... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | srittau |
| 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