Title: Sibling subclasses (without stubs) pass for each other? · Issue #3987 · python/mypy · GitHub
Open Graph Title: Sibling subclasses (without stubs) pass for each other? · Issue #3987 · python/mypy
X Title: Sibling subclasses (without stubs) pass for each other? · Issue #3987 · python/mypy
Description: In what is perhaps a fool's errand, I'm hoping to use mypy to help typecheck code written using a big library without stubs (pytorch). mypy seems to know something about the types of the variables, but not quite enough to be helpful. I'm...
Open Graph Description: In what is perhaps a fool's errand, I'm hoping to use mypy to help typecheck code written using a big library without stubs (pytorch). mypy seems to know something about the types of the variables,...
X Description: In what is perhaps a fool's errand, I'm hoping to use mypy to help typecheck code written using a big library without stubs (pytorch). mypy seems to know something about the types of the va...
Opengraph URL: https://github.com/python/mypy/issues/3987
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Sibling subclasses (without stubs) pass for each other?","articleBody":"In what is perhaps a fool's errand, I'm hoping to use mypy to help typecheck code written using a big library without stubs ([pytorch](http://pytorch.org/)).\r\n\r\nmypy seems to know something about the types of the variables, but not quite enough to be helpful. I'm hoping to understand why the below happens and if there's anything I can do about it.\r\n\r\nCode:\r\n\r\n```python\r\nimport torch\r\n\r\ni = torch.IntTensor()\r\nf = torch.FloatTensor()\r\nreveal_type(i)\r\nreveal_type(f)\r\n\r\ndef foo(i: torch.IntTensor, f: torch.FloatTensor) -> None:\r\n pass\r\n\r\n# these typecheck as expected\r\nfoo(i, f) # OK\r\nfoo(1, 2) # error\r\n\r\n# these typecheck OK, but I think should error\r\nfoo(i, i)\r\nfoo(f, f)\r\n```\r\n\r\nOutput of `mypy --follow-imports=silent`:\r\n```txt\r\n5: error: Revealed type is 'torch.IntTensor'\r\n6: error: Revealed type is 'torch.FloatTensor'\r\n13: error: Argument 1 to \"foo\" has incompatible type \"int\"; expected \"IntTensor\"\r\n13: error: Argument 2 to \"foo\" has incompatible type \"int\"; expected \"FloatTensor\"\r\n```\r\n\r\nI am sorry if this is because of my confusion with python or mypy in general.\r\n\r\n---\r\n\r\nMore info:\r\n- mypy 0.521\r\n- [full output of mypy](https://gist.github.com/mbforbes/0fdf4b842b4f6abde5aaadcc86228547)\r\n\r\nThe definitions of the above classes:\r\n\r\n```python\r\nclass FloatTensor(_C.FloatTensorBase, _TensorBase):\r\n\r\n def is_signed(self):\r\n return True\r\n\r\n @classmethod\r\n def storage_type(cls):\r\n return FloatStorage\r\n\r\nclass IntTensor(_C.IntTensorBase, _TensorBase):\r\n\r\n def is_signed(self):\r\n return True\r\n\r\n @classmethod\r\n def storage_type(cls):\r\n return IntStorage\r\n```\r\n\r\n","author":{"url":"https://github.com/mbforbes","@type":"Person","name":"mbforbes"},"datePublished":"2017-09-22T22:36:17Z","url":"https://github.com/python/mypy/issues/3987"}
| 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:01a5a8cb-1657-f899-6a48-b8592b91acb6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B822:3AAC7B:1108207:16525C5:6B0007DB |
| html-safe-nonce | de39b95baeae156c04abbfb6c2ff6b5cb5ccf766ca20ce42d472a8feca48d157 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODIyOjNBQUM3QjoxMTA4MjA3OjE2NTI1QzU6NkIwMDA3REIiLCJ2aXNpdG9yX2lkIjoiMjEzMDQ4ODAzMDQxMzE5NTIyNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e0f7e03409c9cb96b9a155e9a6590e9e8f78917f452cbfcaae86af61dec658cc |
| hovercard-subject-tag | issue:259954677 |
| 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/3987/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5c3ab6572f872198a8f5d7dd40c87e6efcbae44d7321684a02d0358f4a268b1e/python/mypy/issues/3987 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5c3ab6572f872198a8f5d7dd40c87e6efcbae44d7321684a02d0358f4a268b1e/python/mypy/issues/3987 |
| og:image:alt | In what is perhaps a fool's errand, I'm hoping to use mypy to help typecheck code written using a big library without stubs (pytorch). mypy seems to know something about the types of the variables,... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mbforbes |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width