Title: generics inferred differently when assigning to variable even though the variable's type is the same · Issue #11455 · python/mypy · GitHub
Open Graph Title: generics inferred differently when assigning to variable even though the variable's type is the same · Issue #11455 · python/mypy
X Title: generics inferred differently when assigning to variable even though the variable's type is the same · Issue #11455 · python/mypy
Description: from typing import Callable, TypeVar A = TypeVar("A") B = TypeVar("B") def func(a: A, b: B, fn: Callable[[A], A]) -> A | B: ... inferred = func( 1, None, lambda value: reveal_type(value), # Revealed type is "builtins.int" ) reveal_type(i...
Open Graph Description: from typing import Callable, TypeVar A = TypeVar("A") B = TypeVar("B") def func(a: A, b: B, fn: Callable[[A], A]) -> A | B: ... inferred = func( 1, None, lambda value: reveal_type(value), # Reveale...
X Description: from typing import Callable, TypeVar A = TypeVar("A") B = TypeVar("B") def func(a: A, b: B, fn: Callable[[A], A]) -> A | B: ... inferred = func( 1, None, lambda value: reveal...
Opengraph URL: https://github.com/python/mypy/issues/11455
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"generics inferred differently when assigning to variable even though the variable's type is the same","articleBody":"```py\r\nfrom typing import Callable, TypeVar\r\n\r\nA = TypeVar(\"A\")\r\nB = TypeVar(\"B\")\r\n\r\n\r\ndef func(a: A, b: B, fn: Callable[[A], A]) -\u003e A | B:\r\n ...\r\n\r\n\r\ninferred = func(\r\n 1,\r\n None,\r\n lambda value: reveal_type(value), # Revealed type is \"builtins.int\"\r\n)\r\nreveal_type(inferred) # \"Union[builtins.int, None]\"\r\n\r\nexplicit: int | None\r\nexplicit = func(\r\n 1,\r\n None,\r\n lambda value: reveal_type(value), # Revealed type is \"Union[builtins.int, None]\"\r\n)\r\nreveal_type(explicit) # \"Union[builtins.int, None]\"\r\n```\r\nhttps://mypy-play.net/?mypy=latest\u0026python=3.10\u0026gist=7c2af9e77a6246ee6fb3e5052722eec1","author":{"url":"https://github.com/DetachHead","@type":"Person","name":"DetachHead"},"datePublished":"2021-11-04T08:02:55.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/11455/mypy/issues/11455"}
| 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:f40156dd-5dc6-d9d7-d773-d4e2d3e6264e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D682:257F3:9341B95:C89005B:6A5EB7E6 |
| html-safe-nonce | ed4d0a53e67c54a00c976dca3607c97e70aa17241f38d887c3b8cee99ffadaeb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjgyOjI1N0YzOjkzNDFCOTU6Qzg5MDA1Qjo2QTVFQjdFNiIsInZpc2l0b3JfaWQiOiIyMzA3MDE2MzIzMDQ5MTA5NDc4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 98a336012b90adc43342742cf877cab964079fa2d95ff3e2391033f32a7704e9 |
| hovercard-subject-tag | issue:1044452413 |
| 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/11455/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a2bffe8a5239fb40a3b41f887fb767ba7923ce5f56e02ae022e8e7688ea3c51b/python/mypy/issues/11455 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a2bffe8a5239fb40a3b41f887fb767ba7923ce5f56e02ae022e8e7688ea3c51b/python/mypy/issues/11455 |
| og:image:alt | from typing import Callable, TypeVar A = TypeVar("A") B = TypeVar("B") def func(a: A, b: B, fn: Callable[[A], A]) -> A | B: ... inferred = func( 1, None, lambda value: reveal_type(value), # Reveale... |
| 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 | 4990f88333a33a06a52a934a8f17d4aeb5f4fb5c1d6b3729cb8cdad98dcd3982 |
| 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 | 34c11453111be06b0fea288e6ddc744b8409f8df |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width