-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
Code StyleCode style, linting, code_checksCode style, linting, code_checks
Milestone
Description
Code Sample, a copy-pastable example if possible
While going through the code I observed at couple of places where bool(o)
is being used to check whether the object o
is None
.
Example 1:
Line 449 in 6620dc6
f = lambda x: bool(regex.search(x)) |
Example 2:
Line 821 in 6620dc6
f = lambda x: bool(regex.match(x)) |
Problem description
bool(o)
is several times slower than o is not None
(see below). In the above cases however, majority of the time indeed is being taken by the re.search
and therefore it might not matter for the overall time. But, why not switch to the possibly correct version?
Moreover, the functionality remains the same as re.search
and re.match
return None
when they cannot find a match; which is fundamentally what is being checked in this code.
Metadata
Metadata
Assignees
Labels
Code StyleCode style, linting, code_checksCode style, linting, code_checks