Title: type is not recalculated when it was previously a List[Any] · Issue #8540 · python/mypy · GitHub
Open Graph Title: type is not recalculated when it was previously a List[Any] · Issue #8540 · python/mypy
X Title: type is not recalculated when it was previously a List[Any] · Issue #8540 · python/mypy
Description: Are you reporting a bug, or opening a feature request? A bug Please insert below the code you are checking with mypy, from typing import Any def get_any() -> Any: return {} def fun(message_json) -> int: messages = [get_any()] messages = ...
Open Graph Description: Are you reporting a bug, or opening a feature request? A bug Please insert below the code you are checking with mypy, from typing import Any def get_any() -> Any: return {} def fun(message_json) ->...
X Description: Are you reporting a bug, or opening a feature request? A bug Please insert below the code you are checking with mypy, from typing import Any def get_any() -> Any: return {} def fun(message_json)...
Opengraph URL: https://github.com/python/mypy/issues/8540
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"type is not recalculated when it was previously a List[Any]","articleBody":"* Are you reporting a bug, or opening a feature request?\r\nA bug\r\n* Please insert below the code you are checking with mypy,\r\n```\r\nfrom typing import Any\r\n\r\ndef get_any() -> Any:\r\n return {}\r\n\r\ndef fun(message_json) -> int:\r\n messages = [get_any()]\r\n messages = get_any()\r\n if not isinstance(messages, list):\r\n print(messages)\r\n return 2\r\n```\r\n* What is the actual behavior/output?\r\n```\r\n:12 error: Statement is unreachable [unreachable]\r\n print(messages)\r\n```\r\n* What is the behavior/output you expect?\r\nI would expect one the following:\r\na) Either I get an error because \"messages\" is reassigned to Any afetr it was a list in the previous line\r\nb) Or I don't get the \"unreachable\" error because before the \"if\", \"messages\" can indeed not be a list\r\n \r\nCuriously with the code below, I don't get any error\r\n```\r\nfrom typing import Any\r\n\r\ndef get_any() -> Any:\r\n return {}\r\n\r\ndef fun(message_json) -> int:\r\n messages = [3] # \u003c=== only this line changes\r\n messages = get_any()\r\n if not isinstance(messages, list):\r\n print(messages)\r\n return 2\r\n\r\n```\r\n\r\n* What are the versions of mypy and Python you are using?\r\n0.770 (with 0.761 I got the same error message but with \"misc\" code)\r\n\r\n* What are the mypy flags you are using? (For example --strict-optional)\r\n--show-error-codes --warn-unreachable \r\n\r\n","author":{"url":"https://github.com/dpinol","@type":"Person","name":"dpinol"},"datePublished":"2020-03-15T08:22:39Z","url":"https://github.com/python/mypy/issues/8540"}
| 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:2e06dbd4-0441-0d33-e6dd-ab1f855606f4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C7EE:2E6021:356D254:471CEF4:6B00483D |
| html-safe-nonce | e46b721ca1eadbaac87a45bf88eab3462a71c3f64c9057aa633314c4d06a355e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDN0VFOjJFNjAyMTozNTZEMjU0OjQ3MUNFRjQ6NkIwMDQ4M0QiLCJ2aXNpdG9yX2lkIjoiNTIyODA0NzExMjE3MTg2ODc3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 27a9cd389976c48a8acfc1ecd0dbbb19546e94dfd38c2be3e5caa8ed3cf8a1b6 |
| hovercard-subject-tag | issue:581579486 |
| 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/8540/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7c90b81f11328205a4c8eb8b97de4fdddb5193e98a4e23481acba5b328f5bfb4/python/mypy/issues/8540 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7c90b81f11328205a4c8eb8b97de4fdddb5193e98a4e23481acba5b328f5bfb4/python/mypy/issues/8540 |
| og:image:alt | Are you reporting a bug, or opening a feature request? A bug Please insert below the code you are checking with mypy, from typing import Any def get_any() -> Any: return {} def fun(message_json) ->... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dpinol |
| 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 | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width