Title: Add `__class_getitem__` to `map` builtin, PEP 585 · Issue #108761 · python/cpython · GitHub
Open Graph Title: Add `__class_getitem__` to `map` builtin, PEP 585 · Issue #108761 · python/cpython
X Title: Add `__class_getitem__` to `map` builtin, PEP 585 · Issue #108761 · python/cpython
Description: Feature or enhancement Right now it is impossible to subscribe map: » ./python.exe Python 3.13.0a0 (heads/main-dirty:79823c103b6, Aug 31 2023, 15:46:08) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin Type "help", "copyright", "credits" ...
Open Graph Description: Feature or enhancement Right now it is impossible to subscribe map: » ./python.exe Python 3.13.0a0 (heads/main-dirty:79823c103b6, Aug 31 2023, 15:46:08) [Clang 14.0.3 (clang-1403.0.22.14.1)] on dar...
X Description: Feature or enhancement Right now it is impossible to subscribe map: » ./python.exe Python 3.13.0a0 (heads/main-dirty:79823c103b6, Aug 31 2023, 15:46:08) [Clang 14.0.3 (clang-1403.0.22.14.1)] on dar...
Opengraph URL: https://github.com/python/cpython/issues/108761
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add `__class_getitem__` to `map` builtin, PEP 585 ","articleBody":"# Feature or enhancement\r\n\r\nRight now it is impossible to subscribe `map`:\r\n\r\n```python\r\n» ./python.exe\r\nPython 3.13.0a0 (heads/main-dirty:79823c103b6, Aug 31 2023, 15:46:08) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n\u003e\u003e\u003e map[str]\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\nTypeError: type 'map' is not subscriptable\r\n\u003e\u003e\u003e \r\n```\r\n\r\nI propose adding `__class_getitem__` support to `map`, because it makes sense in some cases.\r\nHowever, https://peps.python.org/pep-0585/ does not say anything about `map`.\r\n\r\nFirst of all, `map` is defined as `Generic` in `typeshed`:\r\n\r\n```python\r\nclass map(Iterator[_S], Generic[_S]):\r\n def __next__(self) -\u003e _S: ...\r\n```\r\n\r\nFull def: https://github.com/python/typeshed/blob/9552ec7f72f3190eb529aec096783c624b43bd29/stdlib/builtins.pyi#L1473-L1514\r\n\r\nSo, any person that wants to, say, return `map[str]` right now has to use `'map[str]'` (via `''` or via `from __future__ import annotations`).\r\n\r\nSecond, while we can treat `map[T]` as just `Iterator[T]` in parameter types, we always want to as specific as possible in return types.\r\n\r\nThird, it is a builtin, so we assume that it is widely used. And it actually is, even in CPython's source itself we can find usages that can be annotated as `map[whatever]`:\r\n- https://github.com/python/cpython/blob/3047f09490ae63f25d57efe1d14a9a65d9b5f6db/Lib/zipfile/_path/__init__.py#L368\r\n- https://github.com/python/cpython/blob/3047f09490ae63f25d57efe1d14a9a65d9b5f6db/Doc/library/itertools.rst#L808\r\n- https://github.com/python/cpython/blob/3047f09490ae63f25d57efe1d14a9a65d9b5f6db/Doc/library/itertools.rst#L964\r\n- https://github.com/python/cpython/blob/3047f09490ae63f25d57efe1d14a9a65d9b5f6db/Doc/library/itertools.rst#L1022\r\n- https://github.com/python/cpython/blob/3047f09490ae63f25d57efe1d14a9a65d9b5f6db/Lib/importlib/resources/readers.py#L76\r\n- https://github.com/python/cpython/blob/3047f09490ae63f25d57efe1d14a9a65d9b5f6db/Lib/logging/config.py#L112\r\n- https://github.com/python/cpython/blob/3047f09490ae63f25d57efe1d14a9a65d9b5f6db/Lib/importlib/metadata/__init__.py#L540\r\n- https://github.com/python/cpython/blob/3047f09490ae63f25d57efe1d14a9a65d9b5f6db/Lib/importlib/metadata/__init__.py#L787\r\n\r\n\r\nLastly, it is a one-line change (+ tests) and many other builtins and stdlib objects support that already.\r\n\r\nI cannot really think of any major cons.\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-108762\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/sobolevn","@type":"Person","name":"sobolevn"},"datePublished":"2023-09-01T12:59:18.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":16},"url":"https://github.com/108761/cpython/issues/108761"}
| 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:7c5acb1b-8058-efa8-a4c3-eb7f8077bca0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8196:378C0F:409185:5A0B19:696A6B02 |
| html-safe-nonce | 53df55db9af062bd9ece0cf75c2fb08d535acaaa4675b0a10c90c86eb44a4a73 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTk2OjM3OEMwRjo0MDkxODU6NUEwQjE5OjY5NkE2QjAyIiwidmlzaXRvcl9pZCI6IjY3OTAwNTI4MTA5MjY0ODQyMjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d1e8c6c8a170295b41fbde6c02ca7b09f144247a94c04a2df25e221e0c01c3c3 |
| hovercard-subject-tag | issue:1877382986 |
| 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/cpython/108761/issue_layout |
| twitter:image | https://opengraph.githubassets.com/17e664e695015f1019bd27d1b93fe6cd7353747c2c1421f9267df057a686cc8f/python/cpython/issues/108761 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/17e664e695015f1019bd27d1b93fe6cd7353747c2c1421f9267df057a686cc8f/python/cpython/issues/108761 |
| og:image:alt | Feature or enhancement Right now it is impossible to subscribe map: » ./python.exe Python 3.13.0a0 (heads/main-dirty:79823c103b6, Aug 31 2023, 15:46:08) [Clang 14.0.3 (clang-1403.0.22.14.1)] on dar... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sobolevn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6fea32d5b7276b841b7a803796d9715bc6cfb31ed549fdf9de2948ac25d12ba6 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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 | f2d9f6432a5a115ec709295ae70623f33bb80aee |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width