Title: Getting a union from an `and` expression · Issue #16565 · python/mypy · GitHub
Open Graph Title: Getting a union from an `and` expression · Issue #16565 · python/mypy
X Title: Getting a union from an `and` expression · Issue #16565 · python/mypy
Description: Bug Report I'd hope there's already an issue for this, but couldn't find one. When using and, mypy infers a union from both sides when the truthy evaluation makes it impossible. Actual code trigerring the error: https://github.com/aio-li...
Open Graph Description: Bug Report I'd hope there's already an issue for this, but couldn't find one. When using and, mypy infers a union from both sides when the truthy evaluation makes it impossible. Actual code trigerr...
X Description: Bug Report I'd hope there's already an issue for this, but couldn't find one. When using and, mypy infers a union from both sides when the truthy evaluation makes it impossible. Actual ...
Opengraph URL: https://github.com/python/mypy/issues/16565
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Getting a union from an `and` expression","articleBody":"**Bug Report**\r\n\r\nI'd hope there's already an issue for this, but couldn't find one.\r\nWhen using `and`, mypy infers a union from both sides when the truthy evaluation makes it impossible.\r\n\r\nActual code trigerring the error: https://github.com/aio-libs/aiohttp/pull/7879/files#diff-720910fd022b9ba8b7ddf0cb446ce5e1afe443f4287ad26a1eb4dc4b5b5f4508R944\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nclass Protocol:\r\n upgraded: bool\r\n\r\nclass Connection:\r\n protocol: Protocol | None\r\n\r\nconn: Connection | None\r\nprotocol = conn and conn.protocol\r\nassert protocol is not None\r\nprotocol.upgraded # error: Item \"Connection\" of \"Connection | Protocol\" has no attribute \"upgraded\" [union-attr]\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nprotocol can't be Connection, so this error shouldn't happen.\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 1.7.1","author":{"url":"https://github.com/Dreamsorcerer","@type":"Person","name":"Dreamsorcerer"},"datePublished":"2023-11-25T23:08:44Z","url":"https://github.com/python/mypy/issues/16565"}
| 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:e0157b28-ff8e-9e55-821c-5264fe2b72e3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BD74:100874:28A93A:346F6C:6AFFC43F |
| html-safe-nonce | 20b23022c5945d21f7cc04108a876366b74539a0fd3639b85cc03dcc24651b84 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDc0OjEwMDg3NDoyOEE5M0E6MzQ2RjZDOjZBRkZDNDNGIiwidmlzaXRvcl9pZCI6IjkwNjM3ODU1ODM4MDQ5MjQ5OTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0f5ac3c45a0b9740899f78259aea2231ca38394db34867b2e0340713a87af654 |
| hovercard-subject-tag | issue:2010824063 |
| 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/16565/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e30f4dad60cf0a0b8ca5adaeafda68eefffbd2e2d023b2adec816061b3b26702/python/mypy/issues/16565 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e30f4dad60cf0a0b8ca5adaeafda68eefffbd2e2d023b2adec816061b3b26702/python/mypy/issues/16565 |
| og:image:alt | Bug Report I'd hope there's already an issue for this, but couldn't find one. When using and, mypy infers a union from both sides when the truthy evaluation makes it impossible. Actual code trigerr... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Dreamsorcerer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1e805b832df235bb21305db712c3b6432920019dfc12cb25b9cb8d3b0c9403cf |
| 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 | 8fa4a54e6871c7908eda1c246ad5972982c0b59d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width