Title: False Positive: MyPy fails to infer type of logging handlers in "a = x if c else y" construct · Issue #13652 · python/mypy · GitHub
Open Graph Title: False Positive: MyPy fails to infer type of logging handlers in "a = x if c else y" construct · Issue #13652 · python/mypy
X Title: False Positive: MyPy fails to infer type of logging handlers in "a = x if c else y" construct · Issue #13652 · python/mypy
Description: To Reproduce mypy -c "import logging; b=False; a:logging.Handler = logging.StreamHandler() if b else logging.FileHandler('test.log')" Expected Behavior Should accept that a is a logging.Handler Actual Behavior
Open Graph Description: To Reproduce mypy -c "import logging; b=False; a:logging.Handler = logging.StreamHandler() if b else logging.FileHandler('test.log')" Expected Behavior Should accept that a is a logging.Handler Act...
X Description: To Reproduce mypy -c "import logging; b=False; a:logging.Handler = logging.StreamHandler() if b else logging.FileHandler('test.log')" Expected Behavior Should accept that a is a l...
Opengraph URL: https://github.com/python/mypy/issues/13652
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False Positive: MyPy fails to infer type of logging handlers in \"a = x if c else y\" construct","articleBody":"**To Reproduce**\r\n\r\n\r\n`mypy -c \"import logging; b=False; a:logging.Handler = logging.StreamHandler() if b else logging.FileHandler('test.log')\"`\r\n\r\n**Expected Behavior**\r\n\r\nShould accept that `a` is a `logging.Handler`\r\n\r\n**Actual Behavior**\r\n\r\n`\u003cstring>:1: error: Incompatible types in assignment (expression has type \"object\", variable has type \"Handler\")`\r\n\r\n**Similar examples that do work**\r\n\r\nHard-coding the condition\r\n```\r\nmypy -c \"import logging; a:logging.Handler = logging.StreamHandler() if False else logging.FileHandler('test.log')\"\r\nSuccess: no issues found in 1 source file\r\n```\r\nUsing integers instead of `logging.Handler`s\r\n```\r\nmypy -c \"b=False; a:int = 0 if b else 1\" \r\nSuccess: no issues found in 1 source file\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.971 (compiled: no)\r\n- Mypy command-line flags: None\r\n- Mypy configuration options from `mypy.ini` (and other config files): None\r\n- Python version used: 3.9.13\r\n- Operating system and version: Windows 10\r\n\r\n","author":{"url":"https://github.com/bennyrowland","@type":"Person","name":"bennyrowland"},"datePublished":"2022-09-12T19:39:34Z","url":"https://github.com/python/mypy/issues/13652"}
| 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:4fc1acda-8784-f7bf-037e-dba110ab5fcf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8A7C:07D0:17849F3:1F11047:6B00274E |
| html-safe-nonce | d2bb267d9393cd3b352a3b9f5a1c875e3d3bc11a9b769f76e39a47c3e1ed9193 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTdDOjA3RDA6MTc4NDlGMzoxRjExMDQ3OjZCMDAyNzRFIiwidmlzaXRvcl9pZCI6IjQ5MzI1MzQ0NDM4OTkzNjUxOTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d0c1c1c5f2108da770ca3130fb6f6af6f272def959bbe31e8fd2dd0df1abac95 |
| hovercard-subject-tag | issue:1370426505 |
| 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/13652/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e22bdf223b1d5788cccfbc1121de5fb96bc64fd04374a3ffdceb0ff63087d4b1/python/mypy/issues/13652 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e22bdf223b1d5788cccfbc1121de5fb96bc64fd04374a3ffdceb0ff63087d4b1/python/mypy/issues/13652 |
| og:image:alt | To Reproduce mypy -c "import logging; b=False; a:logging.Handler = logging.StreamHandler() if b else logging.FileHandler('test.log')" Expected Behavior Should accept that a is a logging.Handler Act... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bennyrowland |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width