Title: Infer union from conditional definition in if statement · Issue #6233 · python/mypy · GitHub
Open Graph Title: Infer union from conditional definition in if statement · Issue #6233 · python/mypy
X Title: Infer union from conditional definition in if statement · Issue #6233 · python/mypy
Description: Maybe if a variable is initialized both in if and else blocks, the resulting type should be the union of the types of the initializers (only when using --allow-redefinitions): if foo(): x = 0 # Type of x is 'int' here else: x = '' # No e...
Open Graph Description: Maybe if a variable is initialized both in if and else blocks, the resulting type should be the union of the types of the initializers (only when using --allow-redefinitions): if foo(): x = 0 # Typ...
X Description: Maybe if a variable is initialized both in if and else blocks, the resulting type should be the union of the types of the initializers (only when using --allow-redefinitions): if foo(): x = 0 # Typ...
Opengraph URL: https://github.com/python/mypy/issues/6233
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Infer union from conditional definition in if statement","articleBody":"Maybe if a variable is initialized both in if and else blocks, the resulting type should be the union of the types of the initializers (only when using `--allow-redefinitions`):\r\n\r\n```py\r\nif foo():\r\n x = 0\r\n # Type of x is 'int' here\r\nelse:\r\n x = '' # No error here\r\n # Type of x is 'str' here\r\nreveal_type(x) # Union[int, str]\r\n```\r\n\r\nCurrently the second assignment generates an error, and the type of `x` is `int` everywhere.\r\n\r\nThis is a generalization of #6232 and related to #1174 (but not a direct follow-up issue).","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2019-01-21T12:30:22Z","url":"https://github.com/python/mypy/issues/6233"}
| 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:a1e99588-54c7-604a-6309-3fe892364f06 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DEC6:31F9AC:2261E7:2FE31F:6B00687C |
| html-safe-nonce | cc2d05dfac76c85bc5998db1c397d927bca261b0659df117856048f1175b7374 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERUM2OjMxRjlBQzoyMjYxRTc6MkZFMzFGOjZCMDA2ODdDIiwidmlzaXRvcl9pZCI6IjY0ODgxMzY4NDM2MzUyMjI2NTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 01d5a8fe6d511fa24ceeab07fe85b52fee5ba426766627490b125a32074a5b01 |
| hovercard-subject-tag | issue:401332414 |
| 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/6233/issue_layout |
| twitter:image | https://opengraph.githubassets.com/678e445de67c3363a8a1256b0ae0c572c177fd68f64600791415fdb9b7d5e823/python/mypy/issues/6233 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/678e445de67c3363a8a1256b0ae0c572c177fd68f64600791415fdb9b7d5e823/python/mypy/issues/6233 |
| og:image:alt | Maybe if a variable is initialized both in if and else blocks, the resulting type should be the union of the types of the initializers (only when using --allow-redefinitions): if foo(): x = 0 # Typ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JukkaL |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| 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 | 46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width