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

login
register
mail settings
Submitter Pierre-Yves David
Date May 8, 2016, 9:35 p.m.
Message ID <26df77f2964575aa87b2.1462743327@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/14975/
State Superseded
Commit 0e9ed09f5fe9c390e60a98426f64bc3a231f7aa0
Headers show

Comments

Pierre-Yves David - May 8, 2016, 9:35 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.
Augie Fackler - May 11, 2016, 1:49 a.m.
On Sun, May 08, 2016 at 11:35:27PM +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@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

[elided bits that look fine]

> 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)

Wat. Please do a resend that includes smf's wording fix.

>    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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

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