Title: MethodType incorrectly rejected as subtype of Callable · Issue #8869 · python/mypy · GitHub
Open Graph Title: MethodType incorrectly rejected as subtype of Callable · Issue #8869 · python/mypy
X Title: MethodType incorrectly rejected as subtype of Callable · Issue #8869 · python/mypy
Description: When I run mypy on the following code: from types import MethodType from typing import Callable def describe(func: Callable[[], None]) -> str: if isinstance(func, MethodType): return 'bound method' else: return 'other callable' class C: ...
Open Graph Description: When I run mypy on the following code: from types import MethodType from typing import Callable def describe(func: Callable[[], None]) -> str: if isinstance(func, MethodType): return 'bound method'...
X Description: When I run mypy on the following code: from types import MethodType from typing import Callable def describe(func: Callable[[], None]) -> str: if isinstance(func, MethodType): return 'bound ...
Opengraph URL: https://github.com/python/mypy/issues/8869
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"MethodType incorrectly rejected as subtype of Callable","articleBody":"When I run mypy on the following code:\r\n\r\n```py\r\nfrom types import MethodType\r\nfrom typing import Callable\r\n\r\ndef describe(func: Callable[[], None]) -> str:\r\n if isinstance(func, MethodType):\r\n return 'bound method'\r\n else:\r\n return 'other callable'\r\n\r\nclass C:\r\n def m(self) -> None:\r\n pass\r\n\r\nprint(describe(C().m))\r\n```\r\n\r\nIt outputs:\r\n\r\n```\r\n$ mypy --warn-unreachable methodtype.py \r\nmethodtype.py:6: error: Statement is unreachable\r\n```\r\n\r\nThis statement is `return 'bound method'`.\r\n\r\nIf you run the test case, you will see \"bound method\" being printed, so the code is reachable in practice.\r\n\r\nFor some reason the problem disappears if the annotation `func: Callable[[], None]` is changed to just `func: Callable`.\r\n\r\nI'm using mypy 0.770 on Python 3.8.2, with the `--warn-unreachable` option.\r\n","author":{"url":"https://github.com/mthuurne","@type":"Person","name":"mthuurne"},"datePublished":"2020-05-21T05:37:23Z","url":"https://github.com/python/mypy/issues/8869"}
| 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:c6785d3c-c35e-4ce5-0589-dbf684a0338d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E908:3AAC7B:1159B7C:16BF2BC:6B000943 |
| html-safe-nonce | 687d550d0e5faf71d575e1a816a1a2f30da1a67ad1030d133a6f19e8fb6f67e0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOTA4OjNBQUM3QjoxMTU5QjdDOjE2QkYyQkM6NkIwMDA5NDMiLCJ2aXNpdG9yX2lkIjoiNzU0MzQ1Mzk4ODA3OTc5ODU5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 17110c408c5130a37407bbadccbed1f30f48d44622060a7b81808c0eadd28c18 |
| hovercard-subject-tag | issue:622260822 |
| 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/8869/issue_layout |
| twitter:image | https://opengraph.githubassets.com/970f8e61c6a4f921791434e46bf379d2e41c2291c42f6c80316e15a2340ed896/python/mypy/issues/8869 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/970f8e61c6a4f921791434e46bf379d2e41c2291c42f6c80316e15a2340ed896/python/mypy/issues/8869 |
| og:image:alt | When I run mypy on the following code: from types import MethodType from typing import Callable def describe(func: Callable[[], None]) -> str: if isinstance(func, MethodType): return 'bound method'... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mthuurne |
| 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