Title: Cannot inference common base class when root of hierarchy is `Any` · Issue #5134 · python/mypy · GitHub
Open Graph Title: Cannot inference common base class when root of hierarchy is `Any` · Issue #5134 · python/mypy
X Title: Cannot inference common base class when root of hierarchy is `Any` · Issue #5134 · python/mypy
Description: I believe this to be a bug code (this has been boiled down from a more complete example) from typing import Type from external import ExtBase class Base(ExtBase): pass class Concrete1(Base): pass class Concrete2(Concrete1): pass def f(x:...
Open Graph Description: I believe this to be a bug code (this has been boiled down from a more complete example) from typing import Type from external import ExtBase class Base(ExtBase): pass class Concrete1(Base): pass c...
X Description: I believe this to be a bug code (this has been boiled down from a more complete example) from typing import Type from external import ExtBase class Base(ExtBase): pass class Concrete1(Base): pass c...
Opengraph URL: https://github.com/python/mypy/issues/5134
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot inference common base class when root of hierarchy is `Any`","articleBody":"I believe this to be a _bug_\r\n\r\n### code\r\n\r\n(this has been boiled down from a more complete example)\r\n\r\n```python\r\nfrom typing import Type\r\n\r\nfrom external import ExtBase\r\n\r\n\r\nclass Base(ExtBase):\r\n pass\r\n\r\n\r\nclass Concrete1(Base):\r\n pass\r\n\r\n\r\nclass Concrete2(Concrete1):\r\n pass\r\n\r\n\r\ndef f(x: Type[Base]) -> None:\r\n pass\r\n\r\n\r\ndef g(x: bool) -> None:\r\n #reveal_type(Base)\r\n #reveal_type(Concrete1)\r\n #reveal_type(Concrete2)\r\n #reveal_type(Concrete1 if x else Concrete2)\r\n f(Concrete1 if x else Concrete2)\r\n```\r\n\r\n### output\r\n\r\n```\r\n$ mypy t2.py --ignore-missing-imports\r\nt2.py:27: error: Argument 1 to \"f\" has incompatible type \"Type[object]\"; expected \"Type[Base]\"\r\n```\r\n\r\n### output with types revealed\r\n\r\n```\r\n$ mypy t2.py --ignore-missing-imports\r\nt2.py:23: error: Revealed type is 'def (*_args: Any, **_kwds: Any) -> t2.Base'\r\nt2.py:24: error: Revealed type is 'def (*_args: Any, **_kwds: Any) -> t2.Concrete1'\r\nt2.py:25: error: Revealed type is 'def (*_args: Any, **_kwds: Any) -> t2.Concrete2'\r\nt2.py:26: error: Revealed type is 'def (*_args: Any, **_kwds: Any) -> builtins.object'\r\nt2.py:27: error: Argument 1 to \"f\" has incompatible type \"Type[object]\"; expected \"Type[Base]\"\r\n```\r\n\r\n### version information\r\n\r\n```\r\n$ mypy --version\r\nmypy 0.600\r\n```\r\n\r\n### against master\r\n\r\nsame error\r\n\r\n### peculiarly working\r\n\r\n```diff\r\ndiff --git a/t2.py b/t2.py\r\nindex 91a8309..6f35532 100644\r\n--- a/t2.py\r\n+++ b/t2.py\r\n@@ -24,4 +24,8 @@ def g(x: bool) -> None:\r\n #reveal_type(Concrete1)\r\n #reveal_type(Concrete2)\r\n #reveal_type(Concrete1 if x else Concrete2)\r\n- f(Concrete1 if x else Concrete2)\r\n+ if x:\r\n+ t = Concrete1\r\n+ else:\r\n+ t = Concrete2\r\n+ f(t)\r\n```","author":{"url":"https://github.com/asottile","@type":"Person","name":"asottile"},"datePublished":"2018-06-01T20:20:12Z","url":"https://github.com/python/mypy/issues/5134"}
| 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:89d554fe-6102-ed0c-5298-91ecd9ed2f03 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 82DA:194E10:2416530:3125920:6B00305B |
| html-safe-nonce | e04da81142da25c9209ec8138f6e2bdc9a3a1131b6e7e381a3db1c2f295e27e1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkRBOjE5NEUxMDoyNDE2NTMwOjMxMjU5MjA6NkIwMDMwNUIiLCJ2aXNpdG9yX2lkIjoiMzY4NTM0NTQxMjIzNjk4MDMxNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5344f0a020c95cd12d8b33630a7c6ff5e6cb9e7ffe5ac5d9c8e14ccbc9b9325a |
| hovercard-subject-tag | issue:328648466 |
| 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/5134/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b0a1e411e756cbc8b088a1883c6544b654b024bef01e2e8481209c4ed95adcf2/python/mypy/issues/5134 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b0a1e411e756cbc8b088a1883c6544b654b024bef01e2e8481209c4ed95adcf2/python/mypy/issues/5134 |
| og:image:alt | I believe this to be a bug code (this has been boiled down from a more complete example) from typing import Type from external import ExtBase class Base(ExtBase): pass class Concrete1(Base): pass c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | asottile |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width