Title: re.Match.group() output doesn't raise type error · Issue #16441 · python/mypy · GitHub
Open Graph Title: re.Match.group() output doesn't raise type error · Issue #16441 · python/mypy
X Title: re.Match.group() output doesn't raise type error · Issue #16441 · python/mypy
Description: # example.py import re def foo(s: str) -> str: print(s) return s m: re.Match[str] | None = re.match('(a)(b)?', 'a') if m is not None: foo(None) # Argument 1 to "foo" has incompatible type "None"; expected "str" [arg-type] # as expected r...
Open Graph Description: # example.py import re def foo(s: str) -> str: print(s) return s m: re.Match[str] | None = re.match('(a)(b)?', 'a') if m is not None: foo(None) # Argument 1 to "foo" has incompatible type "None"; e...
X Description: # example.py import re def foo(s: str) -> str: print(s) return s m: re.Match[str] | None = re.match('(a)(b)?', 'a') if m is not None: foo(None) # Argument 1 to "foo" ha...
Opengraph URL: https://github.com/python/mypy/issues/16441
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"re.Match.group() output doesn't raise type error","articleBody":" ```python\r\n# example.py\r\n\r\nimport re\r\n\r\ndef foo(s: str) -> str:\r\n print(s)\r\n return s\r\n\r\nm: re.Match[str] | None = re.match('(a)(b)?', 'a')\r\n\r\nif m is not None:\r\n foo(None) # Argument 1 to \"foo\" has incompatible type \"None\"; expected \"str\" [arg-type] # as expected\r\n \r\n reveal_type(m.group(2)) # Revealed type is \"Union[builtins.str, Any]\"\r\n foo(m.group(2)) # does not raise an [arg-type] error\r\n assert m.group(2) is None # passes\r\n\r\n```\r\n\r\n```bash\r\n$ mypy --strict example.py \r\nexample.py:12: error: Argument 1 to \"foo\" has incompatible type \"None\"; expected \"str\" [arg-type]\r\nexample.py:14: note: Revealed type is \"Union[builtins.str, Any]\"\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\nWhy doesn't `m.group(2)` raise an [arg-type] error here? \r\n\r\n__Your Environment__\r\n\r\nmypy 1.6.1 (compiled: yes)\r\nPython 3.10.12","author":{"url":"https://github.com/john-dicarlo","@type":"Person","name":"john-dicarlo"},"datePublished":"2023-11-09T18:54:02Z","url":"https://github.com/python/mypy/issues/16441"}
| 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:ba40460f-47a3-e8fa-be56-9cedd7d82295 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DD4C:A1AAC:1EEF1E:2B8DC1:6B005740 |
| html-safe-nonce | b0c6b3cbee9dbfad7a3736868d56c5e7150e0e878fdee720fbe479d12c347aee |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDRDOkExQUFDOjFFRUYxRToyQjhEQzE6NkIwMDU3NDAiLCJ2aXNpdG9yX2lkIjoiODk4NjAwODY0MzgxMTk1NjU0NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 56c5861ed89012f2d5ca86623dd0bf6992f59ac550eab7278b68e1842295e83c |
| hovercard-subject-tag | issue:1986219912 |
| 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/16441/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5fccab2478289f4a238f96e93e141176e6335c072776eeb7ab923ead184df130/python/mypy/issues/16441 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5fccab2478289f4a238f96e93e141176e6335c072776eeb7ab923ead184df130/python/mypy/issues/16441 |
| og:image:alt | # example.py import re def foo(s: str) -> str: print(s) return s m: re.Match[str] | None = re.match('(a)(b)?', 'a') if m is not None: foo(None) # Argument 1 to "foo" has incompatible type "None"; e... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | john-dicarlo |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| 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 | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width