Title: Union[Generic[T], T]] does not work as expected as a parameter in the signature of a generic function · Issue #6417 · python/mypy · GitHub
Open Graph Title: Union[Generic[T], T]] does not work as expected as a parameter in the signature of a generic function · Issue #6417 · python/mypy
X Title: Union[Generic[T], T]] does not work as expected as a parameter in the signature of a generic function · Issue #6417 · python/mypy
Description: Are you reporting a bug, or opening a feature request? Bug Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to simplify your case to a minimal repro. fro...
Open Graph Description: Are you reporting a bug, or opening a feature request? Bug Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to si...
X Description: Are you reporting a bug, or opening a feature request? Bug Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to si...
Opengraph URL: https://github.com/python/mypy/issues/6417
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Union[Generic[T], T]] does not work as expected as a parameter in the signature of a generic function","articleBody":"* Are you reporting a bug, or opening a feature request?\r\n\r\nBug\r\n\r\n* Please insert below the code you are checking with mypy,\r\n or a mock-up repro if the source is private. We would appreciate\r\n if you try to simplify your case to a minimal repro.\r\n```python3\r\nfrom typing import Generic, TypeVar, Union\r\n\r\nF = TypeVar(\"F\")\r\n\r\nclass Z(Generic[F]):\r\n y: F\r\n def __init__(self, y: F):\r\n self.y = y\r\n\r\n\r\ndef q2(x: Union[Z[F], F]) -> F:\r\n if isinstance(x, Z):\r\n return x.y\r\n else:\r\n return x\r\n\r\ndef q3(x: Z[F]) -> F:\r\n return x.y\r\n\r\np = Z('hi')\r\nreveal_type(p) # Z[builtins.str*]\r\nreveal_type(q2) # def [F] (x: Union[Z[F`-1], F`-1]) -> F`-1\r\nq2(p) # error: Argument 1 to \"q2\" has incompatible type \"Z[str]\"; expected \"Z[\u003cnothing>]\"\r\nq3(p) # No error\r\n\r\n```\r\n* What is the actual behavior/output?\r\n\r\nWhen creating a generic function that has a signature where one parameter is a union on a generic of a typevar and that typevar, calling with the generic causes an error.\r\n\r\n* What is the behavior/output you expect?\r\n\r\n`Z[F]` satisfies `Union[Z[F], F]`\r\n\r\n* What are the versions of mypy and Python you are using?\r\n Do you see the same issue after installing mypy from Git master?\r\n\r\nPython 3.6.6, using mypy 0.660; same issue happens with master.\r\n\r\n* What are the mypy flags you are using? (For example --strict-optional)\r\n\r\nNo flags","author":{"url":"https://github.com/haikuginger","@type":"Person","name":"haikuginger"},"datePublished":"2019-02-16T02:37:15Z","url":"https://github.com/python/mypy/issues/6417"}
| 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:8af951a8-fcee-7b67-7664-6f8032b110ca |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C036:1E3154:45F133:5E279C:6B002C77 |
| html-safe-nonce | 259d686fa184e7885973f814a71eb96ab9779b11c9648c398ae22eaa23111581 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDM2OjFFMzE1NDo0NUYxMzM6NUUyNzlDOjZCMDAyQzc3IiwidmlzaXRvcl9pZCI6Ijc3OTA5NzM3ODgyMDA0NTk5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b24b4d9c417a033b3d3c5123afb69cb30556d3df0edebf7e09ed221bbd1de530 |
| hovercard-subject-tag | issue:411016487 |
| 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/6417/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3cadc50627e3b9c011dff501c5233407d75c02ed38e5b092455a017914ed1f6e/python/mypy/issues/6417 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3cadc50627e3b9c011dff501c5233407d75c02ed38e5b092455a017914ed1f6e/python/mypy/issues/6417 |
| og:image:alt | Are you reporting a bug, or opening a feature request? Bug Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to si... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | haikuginger |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width