Title: Use positional only arguments for dunder methods in collections.abc · Issue #14071 · python/typeshed · GitHub
Open Graph Title: Use positional only arguments for dunder methods in collections.abc · Issue #14071 · python/typeshed
X Title: Use positional only arguments for dunder methods in collections.abc · Issue #14071 · python/typeshed
Description: Currently, some dunder methods like Sequence.__getitem__ do not use positional-only arguments, which causes errors when trying to subclass with positional-only arguments. Therefore, dunder methods, especially operators like __getitem__, ...
Open Graph Description: Currently, some dunder methods like Sequence.__getitem__ do not use positional-only arguments, which causes errors when trying to subclass with positional-only arguments. Therefore, dunder methods,...
X Description: Currently, some dunder methods like Sequence.__getitem__ do not use positional-only arguments, which causes errors when trying to subclass with positional-only arguments. Therefore, dunder methods,...
Opengraph URL: https://github.com/python/typeshed/issues/14071
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use positional only arguments for dunder methods in collections.abc","articleBody":"Currently, some dunder methods like `Sequence.__getitem__` do not use positional-only arguments, which causes errors when trying to subclass with positional-only arguments. Therefore, dunder methods, especially operators like `__getitem__`, that are typically not called using keyword arguments, should probably be annotated using positional only arguments in the stubs.\n\nCode sample in [pyright playground](https://pyright-play.net/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoAK4MYAxmADYA0UAygKYXA1gBu9IFYAhgCY0AZJDA7cKAKHGkK3AM6y6AVwQ48shgEdF9FKXoBxejGH0IAQQDaAFQC6ACiJgS5CgEoAXOKjeoAATYcXHxePrz0wFAA%2BpFoRiYQ0XayjMyYKGEAHu5pMK5QALQAfFBW2QB0FSHe-uycPLxVUGER0bHGIgmRSSk0qJnZshRIenlFUABEtMqqMOr0Wjp6hu2mlrbj5ZVSMvJQALJwmtq69Gv2Uyq4s0eLBnEdZzSOzpQejTWB9Y3NUTH3polkkxeul6FkcjQAPSjYqlKAVMrvAJ1YI%2BJrhX5teKAnppfpQQbDehQmF0FKbMreADEUEAMuSSaRyBQXGZzBYnZbxABC1nszzIr08aI%2BKIaaJ%2BrX%2BnW6wLxYOyqBgJIKsIpSNqQTFoQxkpW0qBqT68oJQz0yrGk2mVzZxyWUp56zV2yZ%2B0O81t9Ad5ytahuHPtvKexAFbiFPhFmu%2BOr%2BepxsqN4MV5tV8MqwuRkfF0axHTjhtB4MJZqg0JVZKYFOpUEAoOTiIA)\n\n```python\nfrom typing import Protocol, Self, overload, Literal\n\nclass SupportsSequenceGetitemA[T](Protocol):\n @overload\n def __getitem__(self, index: int) -> T: ...\n @overload\n def __getitem__(self, index: slice) -> \"SupportsSequenceGetitemA[T]\": ...\n\nclass MySequenceA[T](SupportsSequenceGetitemA[T], Protocol):\n @overload\n def __getitem__(self, index: int, /) -> T: ...\n @overload\n def __getitem__(self, index: slice, /) -> Self: ... # ❌\n\nclass SupportsSequenceGetitemB[T](Protocol):\n @overload\n def __getitem__(self, index: int, /) -> T: ...\n @overload\n def __getitem__(self, index: slice, /) -> \"SupportsSequenceGetitemB[T]\": ...\n\nclass MySequenceB[T](SupportsSequenceGetitemB[T], Protocol):\n @overload\n def __getitem__(self, index: int, /) -> T: ...\n @overload\n def __getitem__(self, index: slice, /) -> Self: ... # ✅\n\n```\n","author":{"url":"https://github.com/randolf-scholz","@type":"Person","name":"randolf-scholz"},"datePublished":"2025-05-15T08:52:32Z","url":"https://github.com/python/typeshed/issues/14071"}
| 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:f6c45966-19cd-0ab7-3c53-b4b83874846c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9082:2A087:4DC315:680776:6B002FEB |
| html-safe-nonce | 0b036a31b5ba1211aafb7de3933a4736b06bef01923a5ae9d7fe60217900bfb6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDgyOjJBMDg3OjREQzMxNTo2ODA3NzY6NkIwMDJGRUIiLCJ2aXNpdG9yX2lkIjoiMjY2MjI4NDQ0Mjg0Nzk0ODc3OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b34b432b01c83249cf15446bc623003697594712fc70fb4d751be059f27ca319 |
| hovercard-subject-tag | issue:3065477147 |
| 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/14071/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c51f9b26e5703f2d153c76639e338c2203b41e6dd8cadc7bbdcb4a4dd4733389/python/typeshed/issues/14071 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c51f9b26e5703f2d153c76639e338c2203b41e6dd8cadc7bbdcb4a4dd4733389/python/typeshed/issues/14071 |
| og:image:alt | Currently, some dunder methods like Sequence.__getitem__ do not use positional-only arguments, which causes errors when trying to subclass with positional-only arguments. Therefore, dunder methods,... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | randolf-scholz |
| 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