Title: Overlapping type · Issue #2154 · python/typing · GitHub
Open Graph Title: Overlapping type · Issue #2154 · python/typing
X Title: Overlapping type · Issue #2154 · python/typing
Description: This is an rough idea from the recent discussion of whether to use object/Any or _KT for arguments of certain methods like pop or __sub__. E.g.: class MyPoppable[KT, VT]: def pop(self, x: X) -> VT: ... What should X be? Using KT (or KT |...
Open Graph Description: This is an rough idea from the recent discussion of whether to use object/Any or _KT for arguments of certain methods like pop or __sub__. E.g.: class MyPoppable[KT, VT]: def pop(self, x: X) -> VT:...
X Description: This is an rough idea from the recent discussion of whether to use object/Any or _KT for arguments of certain methods like pop or __sub__. E.g.: class MyPoppable[KT, VT]: def pop(self, x: X) -> ...
Opengraph URL: https://github.com/python/typing/issues/2154
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Overlapping type","articleBody":"This is an rough idea from the recent discussion of whether to use `object`/`Any` or `_KT` for arguments of certain methods like `pop` or `__sub__`. E.g.:\n\n```python\nclass MyPoppable[KT, VT]:\n def pop(self, x: X) -\u003e VT: ...\n```\n\nWhat should `X` be? Using `KT` (or `KT | None`) find type errors like the following:\n\n```python\npoppable: MyPoppable[str]\npoppable.pop(123)\n```\n\nBut has a problem with overlapping types:\n\n```python\ndef foo(x: int | str):\n poppable.pop(x)\n```\n\nOn the other hand, using `object` doesn't catch type errors like `poppable.pop(123)`.\n\nThe solution would be able to specify that any partially overlapping type would be accepted:\n\n```python\nclass MyPoppable[KT, VT]:\n def pop(self, x: Overlapping[KT]) -\u003e VT: ...\n```\n\n`MyPoppable[str]().pop()` would accept `str`, `str | None`, `Literal[\"x\"]`, `str | int`, etc., but not e.g. plain `int`.","author":{"url":"https://github.com/srittau","@type":"Person","name":"srittau"},"datePublished":"2026-01-19T16:36:07.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/2154/typing/issues/2154"}
| 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:f7be49d7-b119-a97a-df30-f6a8d0604afe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E7B6:3DA736:16F6DDC:1E5E56E:696ED182 |
| html-safe-nonce | af89c6d7e04a89aac7fc09f034b5fb7bbe05524e46e852cfda015bd2380f42d4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFN0I2OjNEQTczNjoxNkY2RERDOjFFNUU1NkU6Njk2RUQxODIiLCJ2aXNpdG9yX2lkIjoiMzMxNzY1NTY2NzE4MTgwMTg1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d280cc1d9309e13584f42a4b06e0b2e2099e6cc0c666a302160457625b9cda84 |
| hovercard-subject-tag | issue:3830466102 |
| 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/typing/2154/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2fc9adba9dccdc1f1d768a15f1a2b5b08f45b9963c22211667533ea3189ec4f7/python/typing/issues/2154 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2fc9adba9dccdc1f1d768a15f1a2b5b08f45b9963c22211667533ea3189ec4f7/python/typing/issues/2154 |
| og:image:alt | This is an rough idea from the recent discussion of whether to use object/Any or _KT for arguments of certain methods like pop or __sub__. E.g.: class MyPoppable[KT, VT]: def pop(self, x: X) -> VT:... |
| 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 | b278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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 | 39aed5006635ab6f45e6b77d23e73b08a00272a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width