Title: list.__add__ isn't permissive enough · Issue #8292 · python/typeshed · GitHub
Open Graph Title: list.__add__ isn't permissive enough · Issue #8292 · python/typeshed
X Title: list.__add__ isn't permissive enough · Issue #8292 · python/typeshed
Description: Works at runtime, doesn't type check: class Foo: def asd(self) -> int: return 1 class Bar: def asd(self) -> int: return 2 combined = [Foo()] + [Bar()] for item in combined: print(item.asd()) I would expect [Foo()] + [Bar()] to produce li...
Open Graph Description: Works at runtime, doesn't type check: class Foo: def asd(self) -> int: return 1 class Bar: def asd(self) -> int: return 2 combined = [Foo()] + [Bar()] for item in combined: print(item.asd()) I woul...
X Description: Works at runtime, doesn't type check: class Foo: def asd(self) -> int: return 1 class Bar: def asd(self) -> int: return 2 combined = [Foo()] + [Bar()] for item in combined: print(item.asd...
Opengraph URL: https://github.com/python/typeshed/issues/8292
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"list.__add__ isn't permissive enough","articleBody":"Works at runtime, doesn't type check:\r\n\r\n```python3\r\nclass Foo:\r\n def asd(self) -\u003e int:\r\n return 1\r\n\r\nclass Bar:\r\n def asd(self) -\u003e int:\r\n return 2\r\n\r\ncombined = [Foo()] + [Bar()]\r\nfor item in combined:\r\n print(item.asd())\r\n```\r\n\r\nI would expect `[Foo()] + [Bar()]` to produce `list[Foo | Bar]`.\r\n\r\nConverting to tuples works as expected:\r\n\r\n```python3\r\ncombined = tuple([Foo()]) + tuple([Bar()])\r\n```\r\n\r\nBut invariance problems don't apply here, because we're constructing a new list that doesn't refer to the old lists in any way.\r\n\r\nThere has previously been discussion about how mypy doesn't understand `[Foo(), Bar()]`, but this is slightly different: I'm adding lists, not mixing types within different elements of a single list literal. ","author":{"url":"https://github.com/Akuli","@type":"Person","name":"Akuli"},"datePublished":"2022-07-13T20:36:55.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/8292/typeshed/issues/8292"}
| 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:b5abacc0-0173-a6d6-d41e-7cf0f62dfa99 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DA32:3A10AB:66BEB6:8C4CE0:6A618169 |
| html-safe-nonce | 68d4a8d2074522d346076c2f38d43b5d02d17884ff401e528afae810572e5caf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTMyOjNBMTBBQjo2NkJFQjY6OEM0Q0UwOjZBNjE4MTY5IiwidmlzaXRvcl9pZCI6IjU4MDQwNTQ0NTAwODU2NTg5ODUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 77e9a43a859e7e22e100f061d5912908f97f0a997396a75f6b4fa0eaf4741ff7 |
| hovercard-subject-tag | issue:1303916706 |
| 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/8292/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8fefd96661a09ee2bc9878d734f72a9997d28960b435e15914eb949e429eca4d/python/typeshed/issues/8292 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8fefd96661a09ee2bc9878d734f72a9997d28960b435e15914eb949e429eca4d/python/typeshed/issues/8292 |
| og:image:alt | Works at runtime, doesn't type check: class Foo: def asd(self) -> int: return 1 class Bar: def asd(self) -> int: return 2 combined = [Foo()] + [Bar()] for item in combined: print(item.asd()) I woul... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Akuli |
| hostname | github.com |
| expected-hostname | github.com |
| None | c28c2f6607f2aacbd934868d997038895c9780d08babfe918550d73773326f4c |
| 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 | cd05235d52ffb3318513d883a56c87a121015c8b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width