Title: Better message when inferred variable type conflicts with later use · Issue #2529 · python/mypy · GitHub
Open Graph Title: Better message when inferred variable type conflicts with later use · Issue #2529 · python/mypy
X Title: Better message when inferred variable type conflicts with later use · Issue #2529 · python/mypy
Description: If you can come up with a better name for this issue, please let me know, this one is poor. The naming difficulty also lead to difficulty searching to see if this already existed, so apologies in advance if this is a duplicate issue. Whe...
Open Graph Description: If you can come up with a better name for this issue, please let me know, this one is poor. The naming difficulty also lead to difficulty searching to see if this already existed, so apologies in a...
X Description: If you can come up with a better name for this issue, please let me know, this one is poor. The naming difficulty also lead to difficulty searching to see if this already existed, so apologies in a...
Opengraph URL: https://github.com/python/mypy/issues/2529
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Better message when inferred variable type conflicts with later use","articleBody":"If you can come up with a better name for this issue, please let me know, this one is poor. The naming difficulty also lead to difficulty searching to see if this already existed, so apologies in advance if this is a duplicate issue.\r\n\r\nWhen running this code through the typechecker:\r\n```python\r\nfrom typing import Union, Dict, List\r\ndef g() -> List[Union[str, int]]:\r\n x = ['a']\r\n x += [1]\r\n return x\r\n\r\ndef f() -> Dict[str, Union[str, int]]:\r\n d = {'a': 'a'}\r\n d['b'] = 1\r\n return d\r\n```\r\n\r\nI get this output:\r\n```\r\ntest.py: note: In function \"g\":\r\ntest.py:4: error: List item 0 has incompatible type \"int\"\r\ntest.py:5: error: Incompatible return value type (got List[str], expected List[Union[str, int]])\r\ntest.py: note: In function \"f\":\r\ntest.py:9: error: Incompatible types in assignment (expression has type \"int\", target has type \"str\")\r\ntest.py:10: error: Incompatible return value type (got Dict[str, str], expected Dict[str, Union[str, int]])\r\n```\r\n\r\nWith both these functions, mypy is assuming the type on assignment, then having type errors due to conflicts with the explicitly declared return type.\r\n\r\nSurely there should be a way to correctly infer the original type based on the return type?","author":{"url":"https://github.com/TRManderson","@type":"Person","name":"TRManderson"},"datePublished":"2016-12-06T01:21:35Z","url":"https://github.com/python/mypy/issues/2529"}
| 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:09774db3-6183-12ec-de60-9cb5f593603b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AA70:22BD05:1BF04DA:25A7709:6B00059B |
| html-safe-nonce | 6d97e6e7c1a5e742edf6696e95cb15931896a43091451da973327b2fa798a6dd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTcwOjIyQkQwNToxQkYwNERBOjI1QTc3MDk6NkIwMDA1OUIiLCJ2aXNpdG9yX2lkIjoiNjMyOTQ1MjMwNTEyOTE1ODY3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 19fa70a02cf90c0d285a15d666107110c245c16995b645de70e02c60df82f095 |
| hovercard-subject-tag | issue:193657797 |
| 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/2529/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2bb2fe2a50727b868bf3b74f7f39404be2cbe417d409f49433b06a8493889021/python/mypy/issues/2529 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2bb2fe2a50727b868bf3b74f7f39404be2cbe417d409f49433b06a8493889021/python/mypy/issues/2529 |
| og:image:alt | If you can come up with a better name for this issue, please let me know, this one is poor. The naming difficulty also lead to difficulty searching to see if this already existed, so apologies in a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | TRManderson |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width