Title: False positive on `_` (underscore) as variable name with `disallow-any-expr` · Issue #15253 · python/mypy · GitHub
Open Graph Title: False positive on `_` (underscore) as variable name with `disallow-any-expr` · Issue #15253 · python/mypy
X Title: False positive on `_` (underscore) as variable name with `disallow-any-expr` · Issue #15253 · python/mypy
Description: Bug Report mypy gives a false positive with variable _ (underscore) under certain circumstances (see repro). To Reproduce https://mypy-play.net/?mypy=latest&python=3.8&flags=disallow-any-expr&gist=bca874771ec5eba30815133c9bbd4ab7 from ty...
Open Graph Description: Bug Report mypy gives a false positive with variable _ (underscore) under certain circumstances (see repro). To Reproduce https://mypy-play.net/?mypy=latest&python=3.8&flags=disallow-any-expr&gist=...
X Description: Bug Report mypy gives a false positive with variable _ (underscore) under certain circumstances (see repro). To Reproduce https://mypy-play.net/?mypy=latest&python=3.8&flags=disallow-any-ex...
Opengraph URL: https://github.com/python/mypy/issues/15253
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False positive on `_` (underscore) as variable name with `disallow-any-expr`","articleBody":"**Bug Report**\r\n\r\nmypy gives a false positive with variable `_` (underscore) under certain circumstances (see repro).\r\n\r\n**To Reproduce**\r\n\r\nhttps://mypy-play.net/?mypy=latest&python=3.8&flags=disallow-any-expr&gist=bca874771ec5eba30815133c9bbd4ab7\r\n\r\n```python\r\nfrom typing import Callable, Tuple, TypeVar\r\n\r\nT = TypeVar(\"T\")\r\n\r\ndef wrapper(fn: Callable[[], T]) -> Tuple[T, float]:\r\n return fn(), 1\r\n\r\ndef wrapper2(fn: Callable[[], T]) -> T:\r\n return fn()\r\n\r\ndef func() -> int:\r\n x = 1\r\n return x\r\n\r\ndef a() -> None:\r\n _, c = wrapper(func) # \u003c- 2 errors here\r\n b, c = wrapper(func)\r\n _ = wrapper2(func)\r\n\r\n_, c = wrapper(func)\r\n```\r\n\r\nInterestingly only one line causes the error:\r\n- statement inside a function\r\n- variable named `_`\r\n- wrapper returns a tuple\r\n\r\n**Actual Behavior**\r\n\r\n```\r\nmain.py:16: error: Expression type contains \"Any\" (has type \"Tuple[Any, float]\") [misc]\r\nmain.py:16: error: Expression has type \"Any\" [misc]\r\nFound 2 errors in 1 file (checked 1 source file)\r\n```\r\n\r\n**Your Environment**\r\n\r\n(environment of the playground)\r\n\r\n- Mypy version used: 1.3.0\r\n- Mypy command-line flags: `--disallow-any-expr`\r\n- Python version used: 3.8 (same for other versions)","author":{"url":"https://github.com/lkct","@type":"Person","name":"lkct"},"datePublished":"2023-05-16T13:41:09Z","url":"https://github.com/python/mypy/issues/15253"}
| 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:077de240-bfa7-1d65-7168-ea95f0edafbc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8528:170A32:3EF27:569DF:6B004E5B |
| html-safe-nonce | ed6eeb5c313b27c177388e54a984e1e323485d88b218f1c28483eb2c96a0540f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTI4OjE3MEEzMjozRUYyNzo1NjlERjo2QjAwNEU1QiIsInZpc2l0b3JfaWQiOiIyMzM4NzkwMTA0NTY4NDUwNjUxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | cf994f7ef7a792d9f01e3303e26a7d96fe15b0645a182dad58ed3fabd69e9ccd |
| hovercard-subject-tag | issue:1712056103 |
| 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/15253/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c5c226d0c6fefe2371b2fc72b3ab100c6ed1bff7ef21ff658457840e01a47099/python/mypy/issues/15253 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c5c226d0c6fefe2371b2fc72b3ab100c6ed1bff7ef21ff658457840e01a47099/python/mypy/issues/15253 |
| og:image:alt | Bug Report mypy gives a false positive with variable _ (underscore) under certain circumstances (see repro). To Reproduce https://mypy-play.net/?mypy=latest&python=3.8&flags=disallow-any-expr&gist=... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lkct |
| 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 | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width