[PATCH] D25168: [lit] Compare to None using identity, not equality
Brian Gesiak via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 2 18:22:59 PDT 2016
modocache created this revision.
modocache added reviewers: ddunbar, echristo, beanz.
modocache added a subscriber: llvm-commits.
Herald added a subscriber: mehdi_amini.
In Python, `None` is a singleton, so checking whether a variable is
`None` may be done with `is` or `is not`. This has a slight advantage
over equiality comparisons `== None` and `!= None`, since `__eq__` may
be overridden in Python to produce sometimes unexpected results.
Using `is None` and `is not None` is also recommended practice in
https://www.python.org/dev/peps/pep-0008:
> Comparisons to singletons like `None` should always be done with `is` or
`is not`, never the equality operators.
https://reviews.llvm.org/D25168
Files:
utils/lit/lit/TestRunner.py
utils/lit/lit/main.py
Index: utils/lit/lit/main.py
===================================================================
--- utils/lit/lit/main.py
+++ utils/lit/lit/main.py
@@ -309,7 +309,7 @@
userParams[name] = val
# Decide what the requested maximum indvidual test time should be
- if opts.maxIndividualTestTime != None:
+ if opts.maxIndividualTestTime is not None:
maxIndividualTestTime = opts.maxIndividualTestTime
else:
# Default is zero
@@ -340,7 +340,7 @@
# After test discovery the configuration might have changed
# the maxIndividualTestTime. If we explicitly set this on the
# command line then override what was set in the test configuration
- if opts.maxIndividualTestTime != None:
+ if opts.maxIndividualTestTime is not None:
if opts.maxIndividualTestTime != litConfig.maxIndividualTestTime:
litConfig.note(('The test suite configuration requested an individual'
' test timeout of {0} seconds but a timeout of {1} seconds was'
Index: utils/lit/lit/TestRunner.py
===================================================================
--- utils/lit/lit/TestRunner.py
+++ utils/lit/lit/TestRunner.py
@@ -406,7 +406,7 @@
data = f.read()
except:
data = None
- if data != None:
+ if data is not None:
output_files.append((name, path, data))
results.append(ShellCommandResult(
@@ -786,16 +786,16 @@
if exitCode == 0:
status = Test.PASS
else:
- if timeoutInfo == None:
+ if timeoutInfo is None:
status = Test.FAIL
else:
status = Test.TIMEOUT
# Form the output log.
output = """Script:\n--\n%s\n--\nExit Code: %d\n""" % (
'\n'.join(script), exitCode)
- if timeoutInfo != None:
+ if timeoutInfo is not None:
output += """Timeout: %s\n""" % (timeoutInfo,)
output += "\n"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25168.73227.patch
Type: text/x-patch
Size: 2025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161003/42c9b1a3/attachment.bin>
More information about the llvm-commits
mailing list