Title: `inspect.isfunction` and `inspect.ismethod` · Issue #10117 · python/mypy · GitHub
Open Graph Title: `inspect.isfunction` and `inspect.ismethod` · Issue #10117 · python/mypy
X Title: `inspect.isfunction` and `inspect.ismethod` · Issue #10117 · python/mypy
Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
Open Graph Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
X Description: Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
Opengraph URL: https://github.com/python/mypy
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`inspect.isfunction` and `inspect.ismethod`","articleBody":"**Bug Report**\r\n\r\nI use an union between a callable and a class:\r\n\r\n```python\r\n# example.py\r\n\r\nimport inspect\r\nfrom typing import Union, Callable, Type\r\n\r\n\r\ndef some_func(\r\n error: Union[Callable[..., BaseException], Type[BaseException]]\r\n)->None:\r\n if (inspect.isfunction(error) or inspect.ismethod(error)):\r\n reveal_type(error)\r\n else:\r\n reveal_type(error)\r\n```\r\n\r\nMypy does not infer that the type is `Callable` based on `inspect.isfunction` and `inspect.ismethod`, but still assumes the union:\r\n\r\n```\r\nexample.py:9: note: Revealed type is 'Union[def (*Any, **Any) -> builtins.BaseException, Type[builtins.BaseException]]'\r\nexample.py:11: note: Revealed type is 'Union[def (*Any, **Any) -> builtins.BaseException, Type[builtins.BaseException]]'\r\n```\r\n\r\n**To Reproduce**\r\n\r\nExecute the following command:\r\n\r\n```\r\nmypy example.py\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.812","author":{"url":"https://github.com/mristin","@type":"Person","name":"mristin"},"datePublished":"2021-02-19T19:31:57Z","url":"https://github.com/python/mypy/issues/10117"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:36d013f9-5af9-49e8-b011-0715b4169796 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A7BE:1DD784:2EB501:3ED25C:6B002634 |
| html-safe-nonce | 1a2d636635085900c9ba0f0a8527ba4cb6deb8b49551ad77270fafa8a4644ca7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0JFOjFERDc4NDoyRUI1MDE6M0VEMjVDOjZCMDAyNjM0IiwidmlzaXRvcl9pZCI6IjY1NjcwNzczMjg5MjM0MDM4MjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 92acc3d3c87b81ab68253bba63b5f15d3e9c0504e4048a8145062eb76c5473c4 |
| hovercard-subject-tag | repository:7053637 |
| 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/python/mypy/issues/10117 |
| twitter:image | https://opengraph.githubassets.com/f79ae5636353a0db17350af0a02700f2e9c3bbcf096f9450bf0c369c77cd1022/python/mypy |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f79ae5636353a0db17350af0a02700f2e9c3bbcf096f9450bf0c369c77cd1022/python/mypy |
| og:image:alt | Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub. |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-cache |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width