Title: Inheritance broken when testing isinstance? · Issue #6386 · python/mypy · GitHub
Open Graph Title: Inheritance broken when testing isinstance? · Issue #6386 · python/mypy
X Title: Inheritance broken when testing isinstance? · Issue #6386 · python/mypy
Description: I don't know if I'm running into a bug or I'm just not doing things right. I was able to minimize my problem to this using Python 3.5 and mypy 0.660: from abc import ABC, abstractmethod from typing import Any, Optional, Type, Union class...
Open Graph Description: I don't know if I'm running into a bug or I'm just not doing things right. I was able to minimize my problem to this using Python 3.5 and mypy 0.660: from abc import ABC, abstractmethod from typing...
X Description: I don't know if I'm running into a bug or I'm just not doing things right. I was able to minimize my problem to this using Python 3.5 and mypy 0.660: from abc import ABC, abstractmethod...
Opengraph URL: https://github.com/python/mypy/issues/6386
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inheritance broken when testing isinstance?","articleBody":"I don't know if I'm running into a bug or I'm just not doing things right.\r\n\r\nI was able to minimize my problem to this using Python 3.5 and mypy 0.660:\r\n```\r\nfrom abc import ABC, abstractmethod \r\nfrom typing import Any, Optional, Type, Union \r\n \r\nclass A(ABC): \r\n pass \r\n \r\nclass AA(A): \r\n pass \r\n \r\nclass AB(A): \r\n pass \r\n \r\nclass M(object): \r\n pass \r\n \r\nclass MA(M, AA): \r\n pass \r\n \r\nclass MB(M, AB): \r\n pass \r\n \r\nMYTYPES = Union[MA, MB] \r\n \r\nclass T(object): \r\n def __init__(self, newtype:Type[MYTYPES]=MA) -> None: \r\n assert isinstance(newtype, type(M)) \r\n self._new_type = newtype # type: Type[MYTYPES] \r\n \r\n def test(self) -> A: \r\n ret = self._new_type() \r\n print(type(ret)) \r\n return ret \r\n \r\nx = T() \r\nprint(isinstance(x.test(), A)) # True \r\ny = T(MB) \r\nprint(isinstance(y.test(), A)) # True\r\n```\r\nMy results are:\r\n```\r\n$ python3 -m mypy mixin_test.py\r\nmixin_test.py:27: error: Incompatible types in assignment (expression has type \"Type[M]\", variable has type \"Union[Type[MA], Type[MB]]\")\r\n$ python3 mixin_test.py \r\n\u003cclass '__main__.MA'>\r\nTrue\r\n\u003cclass '__main__.MB'>\r\nTrue\r\n```\r\nIt seems that the assert is causing mypy to not realize that the object is still of type 'A'. I just want to make sure that the item passed in has the MixIn 'M' so that it can support the functions that I need. It is quite possible that I'm approaching this whole thing wrong.\r\n","author":{"url":"https://github.com/rldleblanc","@type":"Person","name":"rldleblanc"},"datePublished":"2019-02-13T19:24:28Z","url":"https://github.com/python/mypy/issues/6386"}
| 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:51b8e80d-f444-7fdb-562d-f7b9e4fa70a1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EE0E:251AC0:C9E84E:10C1761:6B004E5C |
| html-safe-nonce | f28e7ec6f587d1c0e37eb74f1a730cd06f37e68a5f709889e05413986d034a30 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRTBFOjI1MUFDMDpDOUU4NEU6MTBDMTc2MTo2QjAwNEU1QyIsInZpc2l0b3JfaWQiOiIzNjI2NDgzODM4OTI4MDQ3NzA4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ccf5ce80c05a46a6364dcb4b278075717350606790ab91203772d63077b2814c |
| hovercard-subject-tag | issue:409962499 |
| 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/6386/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bc9064d1169175441a2d131142bf252df719c46a6a0b533742ded6c87ff894a9/python/mypy/issues/6386 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bc9064d1169175441a2d131142bf252df719c46a6a0b533742ded6c87ff894a9/python/mypy/issues/6386 |
| og:image:alt | I don't know if I'm running into a bug or I'm just not doing things right. I was able to minimize my problem to this using Python 3.5 and mypy 0.660: from abc import ABC, abstractmethod from typing... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rldleblanc |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| 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 | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width