[PATCH 4 of 4] cleanup: replace False identity testing with an explicit token object

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sun May 8 17:35:27 EDT 2016


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1462469571 -7200
#      Thu May 05 19:32:51 2016 +0200
# Node ID 26df77f2964575aa87b20156ca9c59f9b9e9bfce
# Parent  0bca9eed5d743dc99dac33f7c866fccee4f0168c
# EXP-Topic cleanup
cleanup: replace False identity testing with an explicit token object

The recommended way to check default value (when None is not as option) is a
token object. Identity testing to integer is less explicit and not guaranteed to
work in all implementations.

diff -r 0bca9eed5d74 -r 26df77f29645 mercurial/dirstate.py
--- a/mercurial/dirstate.py	Thu May 05 19:24:35 2016 +0200
+++ b/mercurial/dirstate.py	Thu May 05 19:32:51 2016 +0200
@@ -74,6 +74,8 @@ def _trypending(root, vfs, filename):
                 raise
     return (vfs(filename), False)
 
+_token = object()
+
 class dirstate(object):
 
     def __init__(self, opener, ui, root, validate):
@@ -688,12 +690,12 @@ class dirstate(object):
         self._pl = (parent, nullid)
         self._dirty = True
 
-    def write(self, tr=False):
+    def write(self, tr=_token):
         if not self._dirty:
             return
 
         filename = self._filename
-        if tr is False: # not explicitly specified
+        if tr is _token: # not explicitly specified
             self._ui.deprecwarn('use dirstate.write with '
                                'repo.currenttransaction()',
                                '3.9')
diff -r 0bca9eed5d74 -r 26df77f29645 tests/test-devel-warnings.t
--- a/tests/test-devel-warnings.t	Thu May 05 19:24:35 2016 +0200
+++ b/tests/test-devel-warnings.t	Thu May 05 19:32:51 2016 +0200
@@ -123,7 +123,7 @@
 
   $ hg log -r "oldstyle()" -T '{rev}\n'
   devel-warn: revset "oldstyle" use list instead of smartset
-  (compatibility will be dropped after Mercurial-3.9, update your code.) at: /home/marmoute/src/mercurial-dev/mercurial/revset.py:2335 (mfunc)
+  (compatibility will be dropped after Mercurial-3.9, update your code.) at: *mercurial/revset.py:* (mfunc) (glob)
   0
   $ hg oldanddeprecated
   devel-warn: foorbar is deprecated, go shopping
@@ -145,7 +145,7 @@
    $TESTTMP/buggylocking.py:* in oldanddeprecated (glob)
   $ hg blackbox -l 9
   1970/01/01 00:00:00 bob @cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b (5000)> devel-warn: revset "oldstyle" use list instead of smartset
-  (compatibility will be dropped after Mercurial-3.9, update your code.) at: /home/marmoute/src/mercurial-dev/mercurial/revset.py:2335 (mfunc)
+  (compatibility will be dropped after Mercurial-3.9, update your code.) at: *mercurial/revset.py:* (mfunc) (glob)
   1970/01/01 00:00:00 bob @cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b (5000)> log -r oldstyle() -T {rev}\n exited 0 after * seconds (glob)
   1970/01/01 00:00:00 bob @cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b (5000)> oldanddeprecated
   1970/01/01 00:00:00 bob @cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b (5000)> devel-warn: foorbar is deprecated, go shopping


More information about the Mercurial-devel mailing list