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
re: Match Objects always have a boolean value of True #60508
Comments
re module documentation says: Match Objects always have a boolean value of :const:`True`, so that you can test which is confusing - matched objects have boolean value True, doesn't matched - False. |
The documentation is okay. :func:`match` returns a Match object (which have a boolean value of True) if match and None (which have a boolean value of False) if doesn't match. |
Since the quoted paragraph is distant from where the information about the Match Objects always have a boolean value of |
I don't think the relevant information -- that re match and search return None in the case of no match -- is that distant from the paragraph quoted. This fact is already mentioned FOUR times in the page, in each of the re.match, re.search functions and regex.match, regex.search methods, plus implied by the helper function used in the examples. Personally I think no change is required, but if the docs are going to be changed, I recommend going all the way and showing the usual re idiom with an example: Match Objects always have a boolean value of mo = re.search(pattern, string)
if mo:
process(mo) |
Yeah, distant was a poor choice of words. The issue really comes up if you happen to start reading with that section (say when revisiting the docs with an imperfect memory of what you read before). So, I agree that no change is *required*. But adding the example of "the usual idiom" as you suggest seems like it might be worthwhile. I'm fine with either course of action (or inaction, as the case may be). |
I agree this is unclear - If Match object always have a boolean value of True, it actually prevents me from using simple if statement - what's the point of "if True:" statement? - so the remark that matching functions do not always return match objects has some value. I've submitted a patch. |
Thanks for the patch. Note that :const:`True` should be ``True``. |
New changeset dc96df8556d8 by Ezio Melotti in branch '2.7': New changeset 1805fc284201 by Ezio Melotti in branch '3.2': New changeset 7fde4b4f7e56 by Ezio Melotti in branch '3.3': New changeset 63b45c959a2a by Ezio Melotti in branch 'default': |
Thanks for the patch! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: