Title: Statement is unreachable when checking if `Match[str]`.group(...) type is `None` · Issue #7363 · python/mypy · GitHub
Open Graph Title: Statement is unreachable when checking if `Match[str]`.group(...) type is `None` · Issue #7363 · python/mypy
X Title: Statement is unreachable when checking if `Match[str]`.group(...) type is `None` · Issue #7363 · python/mypy
Description: Hi, I am not entirely sure if this is the right place to report it so please tell me if I should submit the issue somewhere else. Issue type: Bug Problematic code: from typing import Match, Optional import re def some_function(some_match...
Open Graph Description: Hi, I am not entirely sure if this is the right place to report it so please tell me if I should submit the issue somewhere else. Issue type: Bug Problematic code: from typing import Match, Optiona...
X Description: Hi, I am not entirely sure if this is the right place to report it so please tell me if I should submit the issue somewhere else. Issue type: Bug Problematic code: from typing import Match, Optiona...
Opengraph URL: https://github.com/python/mypy/issues/7363
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Statement is unreachable when checking if `Match[str]`.group(...) type is `None`","articleBody":"Hi, I am not entirely sure if this is the right place to report it so please tell me if I should submit the issue somewhere else.\r\n\r\n**Issue type:** Bug\r\n**Problematic code:**\r\n```py\r\nfrom typing import Match, Optional\r\nimport re\r\n\r\n\r\ndef some_function(some_match: Match[str]) -> bool:\r\n maybe_match_group = some_match.group(1)\r\n if maybe_match_group is None:\r\n group_matched = True\r\n else:\r\n group_matched = False\r\n return group_matched\r\n\r\n\r\npattern = re.compile(\"(str)?\")\r\nmatch = pattern.fullmatch(\"\")\r\nif match is not None:\r\n print(some_function(match))\r\n```\r\n**Error message:**\r\n```\r\nmain.py:8: error: Statement is unreachable\r\n```\r\n**Expected behaviour:** \r\nNo error as the statement is reachable (and it's used when you run this code). I tried using `Match[Optional[str]]` to fix this but it's not valid argument for `Match`.\r\nAnother thing to note is that this code will not error if I'll just use `Match` without specifying type of string.\r\n\r\n**Python version:**: 3.7.4\r\n**Mypy version:** 0.730, occurs on master as well\r\n**Mypy flags:** `--warn-unreachable`","author":{"url":"https://github.com/Jackenmen","@type":"Person","name":"Jackenmen"},"datePublished":"2019-08-18T16:43:59Z","url":"https://github.com/python/mypy/issues/7363"}
| 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:7f2a69d9-94e7-df3c-4ff4-a0dcecc24c9d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D2AC:1AC37C:3D9D29:52C2F2:6B002ADC |
| html-safe-nonce | 31a997016db5d3ca00f5931bedc24ec72d348ebaf6dfe096c856e35f583fff15 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMkFDOjFBQzM3QzozRDlEMjk6NTJDMkYyOjZCMDAyQURDIiwidmlzaXRvcl9pZCI6IjI3NjQ4MTE1OTU3NDA2MjE1MzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 389f5b7cfff9f192bd9a973b6aeb8294cb33542a9adce759b143c0afefb639ff |
| hovercard-subject-tag | issue:482013572 |
| 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/7363/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eb4d405037e66569690bbd8f844e592d6cd03b7f94c6ec40f39fbcaab92f94b4/python/mypy/issues/7363 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eb4d405037e66569690bbd8f844e592d6cd03b7f94c6ec40f39fbcaab92f94b4/python/mypy/issues/7363 |
| og:image:alt | Hi, I am not entirely sure if this is the right place to report it so please tell me if I should submit the issue somewhere else. Issue type: Bug Problematic code: from typing import Match, Optiona... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Jackenmen |
| 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