Title: TypeVar resolved to a concrete type using isinstance causes mypy to become confused at the equivalence · Issue #11664 · python/mypy · GitHub
Open Graph Title: TypeVar resolved to a concrete type using isinstance causes mypy to become confused at the equivalence · Issue #11664 · python/mypy
X Title: TypeVar resolved to a concrete type using isinstance causes mypy to become confused at the equivalence · Issue #11664 · python/mypy
Description: Bug Report To Reproduce from typing import Any, Generic, TypeVar T = TypeVar("T") class Foo(Generic[T]): def __init__(self, value: T): self.value = value def identity(value: T) -> Foo[T]: if isinstance(value, str): return Foo(value) retu...
Open Graph Description: Bug Report To Reproduce from typing import Any, Generic, TypeVar T = TypeVar("T") class Foo(Generic[T]): def __init__(self, value: T): self.value = value def identity(value: T) -> Foo[T]: if isinst...
X Description: Bug Report To Reproduce from typing import Any, Generic, TypeVar T = TypeVar("T") class Foo(Generic[T]): def __init__(self, value: T): self.value = value def identity(value: T) -> Foo[...
Opengraph URL: https://github.com/python/mypy/issues/11664
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypeVar resolved to a concrete type using isinstance causes mypy to become confused at the equivalence","articleBody":"**Bug Report**\r\n\r\n**To Reproduce**\r\n\r\n```py\r\nfrom typing import Any, Generic, TypeVar\r\nT = TypeVar(\"T\")\r\n\r\nclass Foo(Generic[T]):\r\n def __init__(self, value: T):\r\n self.value = value\r\n\r\ndef identity(value: T) -> Foo[T]:\r\n if isinstance(value, str):\r\n return Foo(value)\r\n return Foo(value)\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nmypy should be able to tell that in the type-guarded block, `T == str` and use that to qualify the types.\r\n\r\n**Actual Behavior**\r\n\r\nmypy reports an error `Argument 1 to \"Foo\" has incompatible type \"str\"; expected \"T\"` in the type-guarded block in `identity()`.\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.910\r\n- Mypy command-line flags: N/A\r\n- Mypy configuration options from `mypy.ini` (and other config files): N/A\r\n- Python version used: 3.9\r\n- Operating system and version: Windows 10\r\n","author":{"url":"https://github.com/alexkoay","@type":"Person","name":"alexkoay"},"datePublished":"2021-12-05T04:28:32Z","url":"https://github.com/python/mypy/issues/11664"}
| 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:ad91418b-abda-357a-1373-d30e3a02dd33 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 83F8:3E7030:B79FEC:F63693:6B004E7B |
| html-safe-nonce | 116b163f264797a1924270543dc51943ae274c795d193c50087a4174cda14efe |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4M0Y4OjNFNzAzMDpCNzlGRUM6RjYzNjkzOjZCMDA0RTdCIiwidmlzaXRvcl9pZCI6IjIzODA0ODkxNDMxODEzOTc2MjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7d3d71baa1218ceee45dde7feb855f01cc43e9904ed05d49700d968a32fcb436 |
| hovercard-subject-tag | issue:1071369540 |
| 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/11664/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e74fa6c25dbfc4859bcea5bf17018b2fe0a8f82281bc1ac314238447c85db3cd/python/mypy/issues/11664 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e74fa6c25dbfc4859bcea5bf17018b2fe0a8f82281bc1ac314238447c85db3cd/python/mypy/issues/11664 |
| og:image:alt | Bug Report To Reproduce from typing import Any, Generic, TypeVar T = TypeVar("T") class Foo(Generic[T]): def __init__(self, value: T): self.value = value def identity(value: T) -> Foo[T]: if isinst... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alexkoay |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| 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 | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width