diff mbox series

[v2,18/21] git-p4: compare to singletons with "is" and "is not"

Message ID 20220113134728.23192-19-jholdsworth@nvidia.com (mailing list archive)
State Superseded
Headers show
Series git-p4: Various code tidy-ups | expand

Commit Message

Joel Holdsworth Jan. 13, 2022, 1:47 p.m. UTC
PEP8 recommends that comparisons with singletons such as None should be
done with "is" and "is not", and never equality operators.

This guideline is described here:
https://www.python.org/dev/peps/pep-0008/#programming-recommendations

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
---
The previous version of this patch replaced code of the form...

if foo == None:
    ...

...with code of the following form:

if not foo:
    ...

Eric Sunshine pointed out that the latter is not necessarily
functionally equivalent to the former in cases where foo is "", [],
False etc.

Therefore this version of the patch instead replaces the code with the
follow ing:

if foo is None:
    ...

 git-p4.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/git-p4.py b/git-p4.py
index 1de5b1c49d..a42010fbdd 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -930,7 +930,7 @@  def p4Where(depotPath):
             if data[:space] == depotPath:
                 output = entry
                 break
-    if output == None:
+    if output is None:
         return ""
     if output["code"] == "error":
         return ""
@@ -952,7 +952,7 @@  def currentGitBranch():
 
 
 def isValidGitDir(path):
-    return git_dir(path) != None
+    return git_dir(path) is not None
 
 
 def parseRevision(ref):
@@ -4500,7 +4500,7 @@  def main():
     global verbose
     verbose = cmd.verbose
     if cmd.needsGit:
-        if cmd.gitdir == None:
+        if cmd.gitdir is None:
             cmd.gitdir = os.path.abspath(".git")
             if not isValidGitDir(cmd.gitdir):
                 # "rev-parse --git-dir" without arguments will try $PWD/.git