Title: Inferring a more precise type on assignment to a variable with Any type · Issue #2928 · python/mypy · GitHub
Open Graph Title: Inferring a more precise type on assignment to a variable with Any type · Issue #2928 · python/mypy
X Title: Inferring a more precise type on assignment to a variable with Any type · Issue #2928 · python/mypy
Description: Mypy infers the type Any for y after the second assignment: from typing import Any def f(x: Any) -> None: y = x y = 1 reveal_type(y) # Any Inferring int as the type might be less surprising. However, if a variable is explicitly declared ...
Open Graph Description: Mypy infers the type Any for y after the second assignment: from typing import Any def f(x: Any) -> None: y = x y = 1 reveal_type(y) # Any Inferring int as the type might be less surprising. Howeve...
X Description: Mypy infers the type Any for y after the second assignment: from typing import Any def f(x: Any) -> None: y = x y = 1 reveal_type(y) # Any Inferring int as the type might be less surprising. How...
Opengraph URL: https://github.com/python/mypy/issues/2928
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inferring a more precise type on assignment to a variable with Any type","articleBody":"Mypy infers the type `Any` for `y` after the second assignment:\r\n\r\n```\r\nfrom typing import Any\r\n\r\ndef f(x: Any) -> None:\r\n y = x\r\n y = 1\r\n reveal_type(y) # Any\r\n```\r\n\r\nInferring `int` as the type might be less surprising. However, if a variable is explicitly declared with an `Any` type, such as `x` in the above example, it's less clear what would be the right thing to do.\r\n\r\nA more general solution would allow redefining variables with arbitrary new types (#1174).","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2017-03-01T10:21:50Z","url":"https://github.com/python/mypy/issues/2928"}
| 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:e3d87e5b-69f5-fe7a-efbe-8da6396b84aa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 870E:1B0A31:27C1909:36376ED:6B004714 |
| html-safe-nonce | b3a172b19803dac59c016c1c1b074f52adb00eaca947ee555f86cc67503e09aa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzBFOjFCMEEzMToyN0MxOTA5OjM2Mzc2RUQ6NkIwMDQ3MTQiLCJ2aXNpdG9yX2lkIjoiNTgyNTU2NDgyNzQzMDQzODY3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2621ecbf9d6956cc8f968a911345a2dbd2e36ec7efb4dafc59938d5ee77adbcb |
| hovercard-subject-tag | issue:211037338 |
| 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/2928/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8199b3c90d8e7c1af9d2c86c13dfaf7c6d5376d835c6f5ab94ae5aff0a7a01c9/python/mypy/issues/2928 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8199b3c90d8e7c1af9d2c86c13dfaf7c6d5376d835c6f5ab94ae5aff0a7a01c9/python/mypy/issues/2928 |
| og:image:alt | Mypy infers the type Any for y after the second assignment: from typing import Any def f(x: Any) -> None: y = x y = 1 reveal_type(y) # Any Inferring int as the type might be less surprising. Howeve... |
| 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 | 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