-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Match.group can return None #3902
Comments
There is a note in the stubs: Line 549 in 23e380a
This needs to be amended about it being potentially |
@rmorshea Are you working on it? I can submit a patch if you want |
@srittau When I am trying to replicate it since return type of |
@lladhibhutall This should use overloads, e.g. the return type should depend on whether an argument is given, it is 0, another int or a str. |
Note it can return None for (non-zero) numbered groups as well: |
IMO having a false positive (i.e. the return type is |
typeshed generally prefers false negatives over false positives (https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#what-to-include), but maybe Sebastian has an opinion on whether to make Optional the return type of zero, one or both of named and (non-zero) numbered groups. |
It looks like the change was made, and then reverted in #3190 |
Ok, seems like false-positive caused problems. Thanks @hauntsaninja. |
There's also some hope a plugin could improve results here, e.g.: python/mypy#7803 |
This is quite needed for |
Reopening. I believe we should strive towards correctness here and we can ensure this at least somewhat using overloads and literals. |
An ideal solution for mypy users here is a plugin (python/mypy#7803). The no argument case and the However everything else, which comprises most of the usage of As discussed in mypyc/mypyc#676, one option here is to mark the return type as Anecdotally, I literally wrote code today that would trigger a false positive if we instead went with |
Basedmypy works correctly in these cases:
|
All usages of
Match.group
appear to return strings however, for optional named groups it can return None:The text was updated successfully, but these errors were encountered: