Title: Mypy subclass/intersection issue on 1.15.0 · Issue #18912 · python/mypy · GitHub
Open Graph Title: Mypy subclass/intersection issue on 1.15.0 · Issue #18912 · python/mypy
X Title: Mypy subclass/intersection issue on 1.15.0 · Issue #18912 · python/mypy
Description: This code filters using an isinstance call to try to find objects that fit the profile of both Foo and Bar: from abc import ABC from collections.abc import Sequence class Foo(ABC): pass class Bar(ABC): pass class Baz(ABC): pass class Foo...
Open Graph Description: This code filters using an isinstance call to try to find objects that fit the profile of both Foo and Bar: from abc import ABC from collections.abc import Sequence class Foo(ABC): pass class Bar(A...
X Description: This code filters using an isinstance call to try to find objects that fit the profile of both Foo and Bar: from abc import ABC from collections.abc import Sequence class Foo(ABC): pass class Bar(A...
Opengraph URL: https://github.com/python/mypy/issues/18912
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mypy subclass/intersection issue on 1.15.0","articleBody":"This code filters using an `isinstance` call to try to find objects that fit the profile of both `Foo` and `Bar`:\r\n\r\n```python\r\nfrom abc import ABC\r\nfrom collections.abc import Sequence\r\n\r\nclass Foo(ABC):\r\n pass\r\n\r\nclass Bar(ABC):\r\n pass\r\n\r\nclass Baz(ABC):\r\n pass\r\n\r\nclass FooBar(Foo, Bar):\r\n pass\r\n\r\nclass FooBaz(Foo, Baz):\r\n pass\r\n\r\ndef my_func(foos: list[Foo]) -\u003e Sequence[Foo]:\r\n my_list = []\r\n for foo in foos:\r\n if not isinstance(foo, Bar):\r\n continue\r\n my_list.append(foo)\r\n return my_list\r\n\r\nfoos = [FooBar(), FooBaz()]\r\nmy_func(foos)\r\n```\r\n\r\nThis code does not fail on Mypy 1.14.1:\r\n\r\nhttps://mypy-play.net/?mypy=1.14.1\u0026python=3.12\u0026gist=7b5be66ab0fb3f04d15a99317ef21a7d\r\n\r\nBut it does fail on Mypy 1.15:\r\n\r\n```\r\nmain.py:24: error: Argument 1 to \"append\" of \"list\" has incompatible type \"__main__.\u003csubclass of \"Foo\" and \"Bar\"\u003e1\"; expected \"__main__.\u003csubclass of \"Foo\" and \"Bar\"\u003e\" [arg-type]\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\nhttps://mypy-play.net/?mypy=1.15.0\u0026python=3.12\u0026gist=7b5be66ab0fb3f04d15a99317ef21a7d\r\n\r\n_Originally posted by @gandhis1 in https://github.com/python/typing/discussions/1968_","author":{"url":"https://github.com/gandhis1","@type":"Person","name":"gandhis1"},"datePublished":"2025-04-12T12:47:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/18912/mypy/issues/18912"}
| 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:8ef1207e-7bcb-6ed8-dc21-76bf47f06ae2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 87F2:1287D0:655D60:87C0B9:6A5B76A5 |
| html-safe-nonce | 1cf9ca89e897882229634ee10225c16185e582f87c82e36a967da872ed3c54fe |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0YyOjEyODdEMDo2NTVENjA6ODdDMEI5OjZBNUI3NkE1IiwidmlzaXRvcl9pZCI6IjM0ODYzNjE1MDE1NDc4NTM0NzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b6e4ca5f1d403add21b7b213bcb9c4e4a96f01ec0b71bad6ef1113d8ff3d28bb |
| hovercard-subject-tag | issue:2990456581 |
| 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/mypy/18912/issue_layout |
| twitter:image | https://opengraph.githubassets.com/96655806cd66a3a99ea8746164e8003ab2951d77c9983489175ffdb5751b4ed8/python/mypy/issues/18912 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/96655806cd66a3a99ea8746164e8003ab2951d77c9983489175ffdb5751b4ed8/python/mypy/issues/18912 |
| og:image:alt | This code filters using an isinstance call to try to find objects that fit the profile of both Foo and Bar: from abc import ABC from collections.abc import Sequence class Foo(ABC): pass class Bar(A... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gandhis1 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width