Title: regex group class should return `AnyStr | None` instead of `AnyStr | Any` · Issue #10526 · python/typeshed · GitHub
Open Graph Title: regex group class should return `AnyStr | None` instead of `AnyStr | Any` · Issue #10526 · python/typeshed
X Title: regex group class should return `AnyStr | None` instead of `AnyStr | Any` · Issue #10526 · python/typeshed
Description: Every time when using the regex library I'm stumbling over this when extracting the group text from a regex match. From what I read the function returns the match as an AnyStr which corresponds to the type variable of the Match[AnyStr]. ...
Open Graph Description: Every time when using the regex library I'm stumbling over this when extracting the group text from a regex match. From what I read the function returns the match as an AnyStr which corresponds to ...
X Description: Every time when using the regex library I'm stumbling over this when extracting the group text from a regex match. From what I read the function returns the match as an AnyStr which corresponds...
Opengraph URL: https://github.com/python/typeshed/issues/10526
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"regex group class should return `AnyStr | None` instead of `AnyStr | Any`","articleBody":"Every time when using the regex library I'm stumbling over this when extracting the group text from a regex match. From what I read the function returns the match as an AnyStr which corresponds to the type variable of the `Match[AnyStr]`. But it also returns Any. I don't possibly know how to return anything else from this method.\r\n\r\nIf a match was successful the group method will do one of the following:\r\n1. The last text matched by the capturing group (either by name or number) as an AnyStr type `(?P\u003cgroupname>.+)`\r\n2. `None` if the capturing group was part of a regex branch that did not match `(\\d+)|(\\w+)`\r\n3. The Error `IndexError(\"no such group\")` if a group was referred that is not part of the pattern.\r\n\r\n[This](https://github.com/python/typeshed/blob/d62cbb98f4ecc2d46bcacfe49cea97bc4efb0ed6/stdlib/re.pyi#L77C58-L77C58) is the method and [here](https://github.com/python/typeshed/blob/d62cbb98f4ecc2d46bcacfe49cea97bc4efb0ed6/stdlib/re.pyi#L73C1-L73C1) is the comment that argues similar.\r\n\r\nThe same problem can be observed in the following places:\r\n- [group(self, __group)](https://github.com/python/typeshed/blob/d62cbb98f4ecc2d46bcacfe49cea97bc4efb0ed6/stdlib/re.pyi#L77)\r\n- [group(self, __group1, __group2, *groups)](https://github.com/python/typeshed/blob/d62cbb98f4ecc2d46bcacfe49cea97bc4efb0ed6/stdlib/re.pyi#L79)\r\n- [groups(self)](https://github.com/python/typeshed/blob/d62cbb98f4ecc2d46bcacfe49cea97bc4efb0ed6/stdlib/re.pyi#L83C44-L83C44)\r\n- [groupdict(self)](https://github.com/python/typeshed/blob/d62cbb98f4ecc2d46bcacfe49cea97bc4efb0ed6/stdlib/re.pyi#L89)\r\n- [\\_\\_getitem__(self)](https://github.com/python/typeshed/blob/d62cbb98f4ecc2d46bcacfe49cea97bc4efb0ed6/stdlib/re.pyi#L101)\r\n\r\nNote: I'm not a professional and I don't even know if this is the right repository for this issue, but I didn't find any better guidance on where to post this.\r\n\r\nThe advantages of the `AnyStr | None` annotation would be:\r\n- null coalescion: `text: str = match.group(1) or \"default\"`\r\n- branching: `if match.group(1): print(\"Match group 1 has matched something\")`","author":{"url":"https://github.com/cn-ml","@type":"Person","name":"cn-ml"},"datePublished":"2023-08-01T13:54:44Z","url":"https://github.com/python/typeshed/issues/10526"}
| 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:a4797a16-6602-6a91-b948-cb3bc4dcf8a1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E8D6:3E4AC7:28B58F2:374EBEA:6B004501 |
| html-safe-nonce | d19b409bfadfce6fb5bee3b8419a4f1d63cc0c3e31cde642675765c6196899f1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOEQ2OjNFNEFDNzoyOEI1OEYyOjM3NEVCRUE6NkIwMDQ1MDEiLCJ2aXNpdG9yX2lkIjoiNDA4MTAyODI2ODA0MjUwMzQyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 692393935d605b18237147ff321de3403de26053ec83a88051de296900fc2fda |
| hovercard-subject-tag | issue:1831346905 |
| 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/typeshed/10526/issue_layout |
| twitter:image | https://opengraph.githubassets.com/016ebbe5b07b2511cef06a2aa848ba2aa69233eb5c578c8493bb4eb1d4a5eb23/python/typeshed/issues/10526 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/016ebbe5b07b2511cef06a2aa848ba2aa69233eb5c578c8493bb4eb1d4a5eb23/python/typeshed/issues/10526 |
| og:image:alt | Every time when using the regex library I'm stumbling over this when extracting the group text from a regex match. From what I read the function returns the match as an AnyStr which corresponds to ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cn-ml |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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