Title: `Callable` used as condition silently disables type checks · Issue #11164 · python/mypy · GitHub
Open Graph Title: `Callable` used as condition silently disables type checks · Issue #11164 · python/mypy
X Title: `Callable` used as condition silently disables type checks · Issue #11164 · python/mypy
Description: Bug Report If the condition of an if block is a Callable (or not Callable), the body of the else (or if) is not analyzed by mypy. To Reproduce Run mypy on: def func() -> bool: return True if not func: a: str = 4 reveal_type(a) else: b: s...
Open Graph Description: Bug Report If the condition of an if block is a Callable (or not Callable), the body of the else (or if) is not analyzed by mypy. To Reproduce Run mypy on: def func() -> bool: return True if not fu...
X Description: Bug Report If the condition of an if block is a Callable (or not Callable), the body of the else (or if) is not analyzed by mypy. To Reproduce Run mypy on: def func() -> bool: return True if not...
Opengraph URL: https://github.com/python/mypy/issues/11164
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`Callable` used as condition silently disables type checks","articleBody":"**Bug Report**\r\n\r\nIf the condition of an `if` block is a `Callable` (or `not Callable`), the body of the `else` (or `if`) is not analyzed by mypy.\r\n\r\n**To Reproduce**\r\n\r\nRun `mypy` on:\r\n\r\n```python\r\ndef func() -> bool:\r\n return True\r\n\r\nif not func:\r\n a: str = 4\r\n reveal_type(a)\r\nelse:\r\n b: str = 4\r\n reveal_type(b)\r\n\r\nif func:\r\n c: str = 4\r\n reveal_type(c)\r\nelse:\r\n d: str = 4\r\n reveal_type(d)\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nEither:\r\n```\r\ntest.py:5: error: Incompatible types in assignment (expression has type \"int\", variable has type \"str\")\r\ntest.py:6: note: Revealed type is \"builtins.str\"\r\ntest.py:8: error: Incompatible types in assignment (expression has type \"int\", variable has type \"str\")\r\ntest.py:9: note: Revealed type is \"builtins.str\"\r\ntest.py:12: error: Incompatible types in assignment (expression has type \"int\", variable has type \"str\")\r\ntest.py:13: note: Revealed type is \"builtins.str\"\r\ntest.py:15: error: Incompatible types in assignment (expression has type \"int\", variable has type \"str\")\r\ntest.py:16: note: Revealed type is \"builtins.str\"\r\n```\r\n\r\nor maybe `statement-unreachable` on lines 5 and 15?\r\n\r\n**Actual Behavior**\r\n\r\n```\r\ntest.py:8: error: Incompatible types in assignment (expression has type \"int\", variable has type \"str\")\r\ntest.py:9: note: Revealed type is \"builtins.str\"\r\ntest.py:12: error: Incompatible types in assignment (expression has type \"int\", variable has type \"str\")\r\ntest.py:13: note: Revealed type is \"builtins.str\"\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: `0.910`\r\n- Mypy command-line flags: Just `mypy test.py`.\r\n- Mypy configuration options from `mypy.ini` (and other config files): None\r\n- Python version used: `3.8.3`\r\n- Operating system and version: Windows 10 Pro 21H1\r\n","author":{"url":"https://github.com/selimb","@type":"Person","name":"selimb"},"datePublished":"2021-09-21T20:58:51Z","url":"https://github.com/python/mypy/issues/11164"}
| 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:ffedb88c-18ff-450b-d7c2-521aa1394537 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AEA2:1A12A9:5BB650:7A787D:6B003338 |
| html-safe-nonce | de9c7f4c32520e768358f47c4ddf4540fb81db599ed4497dfd54eb4929ff47c0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUEyOjFBMTJBOTo1QkI2NTA6N0E3ODdEOjZCMDAzMzM4IiwidmlzaXRvcl9pZCI6IjQwMjM2NDc5NzMxMTkzNzQxMzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 06a3b249ea619345bbb210693f3421d71b36a1e08f34df15b38f6731eb44af76 |
| hovercard-subject-tag | issue:1003271619 |
| 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/11164/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f7e8fb5777e4472ff98bf0663df86abeff1f046bb7bdbbcf6b1bdd29af0a49a7/python/mypy/issues/11164 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f7e8fb5777e4472ff98bf0663df86abeff1f046bb7bdbbcf6b1bdd29af0a49a7/python/mypy/issues/11164 |
| og:image:alt | Bug Report If the condition of an if block is a Callable (or not Callable), the body of the else (or if) is not analyzed by mypy. To Reproduce Run mypy on: def func() -> bool: return True if not fu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | selimb |
| 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