Title: generic incorrectly narrowed based on first parameter in the else branch of an if expression · Issue #11049 · python/mypy · GitHub
Open Graph Title: generic incorrectly narrowed based on first parameter in the else branch of an if expression · Issue #11049 · python/mypy
X Title: generic incorrectly narrowed based on first parameter in the else branch of an if expression · Issue #11049 · python/mypy
Description: from typing import TypeVar T1 = TypeVar("T1") T2 = TypeVar("T2") def foo(a: T1, b: T2) -> T1 | T2: return a invalid = 1 if 1 else foo(1, "s") # error: Argument 2 to "foo" has incompatible type "str"; expected "int" valid = foo(1, "s") if...
Open Graph Description: from typing import TypeVar T1 = TypeVar("T1") T2 = TypeVar("T2") def foo(a: T1, b: T2) -> T1 | T2: return a invalid = 1 if 1 else foo(1, "s") # error: Argument 2 to "foo" has incompatible type "str...
X Description: from typing import TypeVar T1 = TypeVar("T1") T2 = TypeVar("T2") def foo(a: T1, b: T2) -> T1 | T2: return a invalid = 1 if 1 else foo(1, "s") # error: Argument 2 to...
Opengraph URL: https://github.com/python/mypy/issues/11049
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"generic incorrectly narrowed based on first parameter in the else branch of an if expression","articleBody":"```py\r\nfrom typing import TypeVar\r\n\r\nT1 = TypeVar(\"T1\")\r\nT2 = TypeVar(\"T2\")\r\n\r\n\r\ndef foo(a: T1, b: T2) -> T1 | T2:\r\n return a\r\n\r\ninvalid = 1 if 1 else foo(1, \"s\") # error: Argument 2 to \"foo\" has incompatible type \"str\"; expected \"int\"\r\nvalid = foo(1, \"s\") if 1 else 1\r\n```\r\nhttps://mypy-play.net/?mypy=latest&python=3.10&gist=791645f9a348afc114cf3769ed85c30a","author":{"url":"https://github.com/DetachHead","@type":"Person","name":"DetachHead"},"datePublished":"2021-09-03T01:15:23Z","url":"https://github.com/python/mypy/issues/11049"}
| 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:d0823ee8-bc71-ea9e-67ed-4088087f8225 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A222:106F5D:A3688:DCCBF:6B001C36 |
| html-safe-nonce | d45b9c0bb660fd7ad3c7ea390faee9f49e4535a841931406cd80c6e5fe86f856 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjIyOjEwNkY1RDpBMzY4ODpEQ0NCRjo2QjAwMUMzNiIsInZpc2l0b3JfaWQiOiIxMzQ1NjkxMjkwODkyNzcwMzU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2918e9759191834b723851d3bab86eb97b36cde5e30a3d2d7af839fe9c42d3ee |
| hovercard-subject-tag | issue:987302994 |
| 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/11049/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a025c4b329bfd4f0aa29c302d5ee9ba85a854a6cb6de16e83ca294dd52946222/python/mypy/issues/11049 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a025c4b329bfd4f0aa29c302d5ee9ba85a854a6cb6de16e83ca294dd52946222/python/mypy/issues/11049 |
| og:image:alt | from typing import TypeVar T1 = TypeVar("T1") T2 = TypeVar("T2") def foo(a: T1, b: T2) -> T1 | T2: return a invalid = 1 if 1 else foo(1, "s") # error: Argument 2 to "foo" has incompatible type "str... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DetachHead |
| 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