Patchwork D10014: debugcommands: prevent using `is False`

login
register
mail settings
Submitter phabricator
Date Feb. 17, 2021, 7:44 p.m.
Message ID <differential-rev-PHID-DREV-vpoos7de46olaqa5ob65-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48331/
State New
Headers show

Comments

phabricator - Feb. 17, 2021, 7:44 p.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I was touching this code in a future patch and marmoute warned about usage of
  `is False` here.
  
  Quoting marmoute:
  
    "is False" is going to check if the object you have the very same object in
    memory than the one Python allocated for False (in practice 0)
    This will "mostly work" on cpython because of implementation details, but
    is semantically wrong and can start breaking unexpectedly

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10014

AFFECTED FILES
  mercurial/debugcommands.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -3870,10 +3870,10 @@ 
         tagsnode = cache.getfnode(node, computemissing=False)
         if tagsnode:
             tagsnodedisplay = hex(tagsnode)
-        elif tagsnode is False:
+        elif tagsnode is None:
+            tagsnodedisplay = b'missing'
+        else:
             tagsnodedisplay = b'invalid'
-        else:
-            tagsnodedisplay = b'missing'
 
         ui.write(b'%d %s %s\n' % (r, hex(node), tagsnodedisplay))