-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
In Doc/library/re.rst rename a variable from match to m
#123003
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1357,9 +1357,9 @@ Since :meth:`~Pattern.match` and :meth:`~Pattern.search` return ``None`` | |||||||||||||||||||||||||||||||||
| when there is no match, you can test whether there was a match with a simple | ||||||||||||||||||||||||||||||||||
| ``if`` statement:: | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| match = re.search(pattern, string) | ||||||||||||||||||||||||||||||||||
| if match: | ||||||||||||||||||||||||||||||||||
| process(match) | ||||||||||||||||||||||||||||||||||
| m = re.search(pattern, string) | ||||||||||||||||||||||||||||||||||
| if m: | ||||||||||||||||||||||||||||||||||
| process(m) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+1379
to
+1381
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To promote good practice, we could suggest
Suggested change
If we want to suggest using assignment expressions, we could also use:
Suggested change
Or both! (I probably wouldn't go for this...)
Suggested change
A There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having
and
Now, the first does not apply here, because, as the documentation immediately before the example says,
On the other hand, the spirit of the second excerpt from PEP 8 argues for availing of truthiness and falsiness and thus against the redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not have a strong opinion on whether to use the assignment operator here. (I myself would not, reserving it for cases like [process(m) for pattern in patterns if (m := re.search(pattern, string)]and if ...:
...
elif (m := re.search(pattern, string):
process(m)). |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| .. class:: Match | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Adam that the example should be updated, but the text should be updated accordingly.