Patchwork [py3] global: add __bool__ to every class defining __nonzero__

login
register
mail settings
Submitter Gregory Szorc
Date March 13, 2017, 7:40 p.m.
Message ID <a00f6470c72774efa74b.1489434049@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/19300/
State Accepted
Headers show

Comments

Gregory Szorc - March 13, 2017, 7:40 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1489434014 25200
#      Mon Mar 13 12:40:14 2017 -0700
# Node ID a00f6470c72774efa74b04ed46e5d0918224de0a
# Parent  e6b177a3a7662366e8af0ba07ccbd9509a8cc647
global: add __bool__ to every class defining __nonzero__

__nonzero__ was renamed to __bool__ in Python 3. This patch simply
aliases __bool__ to __nonzero__ for every class implementing
__nonzero__.
Yuya Nishihara - March 17, 2017, 1:36 p.m.
On Mon, 13 Mar 2017 12:40:49 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1489434014 25200
> #      Mon Mar 13 12:40:14 2017 -0700
> # Node ID a00f6470c72774efa74b04ed46e5d0918224de0a
> # Parent  e6b177a3a7662366e8af0ba07ccbd9509a8cc647
> global: add __bool__ to every class defining __nonzero__
> 
> __nonzero__ was renamed to __bool__ in Python 3. This patch simply
> aliases __bool__ to __nonzero__ for every class implementing
> __nonzero__.

Seems fine. Queued, thanks.
Yuya Nishihara - March 17, 2017, 1:46 p.m.
On Mon, 13 Mar 2017 12:40:49 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1489434014 25200
> #      Mon Mar 13 12:40:14 2017 -0700
> # Node ID a00f6470c72774efa74b04ed46e5d0918224de0a
> # Parent  e6b177a3a7662366e8af0ba07ccbd9509a8cc647
> global: add __bool__ to every class defining __nonzero__
> 
> __nonzero__ was renamed to __bool__ in Python 3. This patch simply
> aliases __bool__ to __nonzero__ for every class implementing
> __nonzero__.

Got check-code error. I've adjusted the rule to not catch __bool__ aliases.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -164,6 +164,7 @@  def gettimer(ui, opts=None):
                     self.hexfunc = node.short
             def __nonzero__(self):
                 return False
+            __bool__ = __nonzero__
             def startitem(self):
                 pass
             def data(self, **data):
diff --git a/mercurial/ancestor.py b/mercurial/ancestor.py
--- a/mercurial/ancestor.py
+++ b/mercurial/ancestor.py
@@ -296,6 +296,8 @@  class lazyancestors(object):
         except StopIteration:
             return False
 
+    __bool__ = __nonzero__
+
     def __iter__(self):
         """Generate the ancestors of _initrevs in reverse topological order.
 
diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -271,6 +271,8 @@  class unbundlerecords(object):
     def __nonzero__(self):
         return bool(self._sequences)
 
+    __bool__ = __nonzero__
+
 class bundleoperation(object):
     """an object that represents a single bundling process
 
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -532,6 +532,8 @@  class changectx(basectx):
     def __nonzero__(self):
         return self._rev != nullrev
 
+    __bool__ = __nonzero__
+
     @propertycache
     def _changeset(self):
         return self._repo.changelog.changelogrevision(self.rev())
@@ -720,6 +722,8 @@  class basefilectx(object):
             # file is missing
             return False
 
+    __bool__ = __nonzero__
+
     def __str__(self):
         try:
             return "%s@%s" % (self.path(), self._changectx)
@@ -1236,6 +1240,8 @@  class committablectx(basectx):
     def __nonzero__(self):
         return True
 
+    __bool__ = __nonzero__
+
     def _buildflagfunc(self):
         # Create a fallback function for getting file flags when the
         # filesystem doesn't support them
@@ -1709,6 +1715,8 @@  class committablefilectx(basefilectx):
     def __nonzero__(self):
         return True
 
+    __bool__ = __nonzero__
+
     def linkrev(self):
         # linked to self._changectx no matter if file is modified or not
         return self.rev()
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -72,6 +72,8 @@  class revnav(object):
         """return True if any revision to navigate over"""
         return self._first() is not None
 
+    __bool__ = __nonzero__
+
     def _first(self):
         """return the minimum non-filtered changeset or None"""
         try:
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -583,6 +583,8 @@  class localrepository(object):
     def __nonzero__(self):
         return True
 
+    __bool__ = __nonzero__
+
     def __len__(self):
         return len(self.changelog)
 
diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -431,6 +431,8 @@  class manifestdict(object):
         # makes it easier for extensions to override.
         return len(self._lm) != 0
 
+    __bool__ = __nonzero__
+
     def __setitem__(self, key, node):
         self._lm[key] = node, self.flags(key, '')
 
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -552,6 +552,8 @@  class obsstore(object):
                 pass
         return bool(self._all)
 
+    __bool__ = __nonzero__
+
     @property
     def readonly(self):
         """True if marker creation is disabled
diff --git a/mercurial/smartset.py b/mercurial/smartset.py
--- a/mercurial/smartset.py
+++ b/mercurial/smartset.py
@@ -40,6 +40,8 @@  class abstractsmartset(object):
         """True if the smartset is not empty"""
         raise NotImplementedError()
 
+    __bool__ = __nonzero__
+
     def __contains__(self, rev):
         """provide fast membership testing"""
         raise NotImplementedError()
@@ -267,6 +269,8 @@  class baseset(abstractsmartset):
     def __nonzero__(self):
         return bool(len(self))
 
+    __bool__ = __nonzero__
+
     def sort(self, reverse=False):
         self._ascending = not bool(reverse)
         self._istopo = False
@@ -420,6 +424,8 @@  class filteredset(abstractsmartset):
             return True
         return False
 
+    __bool__ = __nonzero__
+
     def __len__(self):
         # Basic implementation to be changed in future patches.
         # until this gets improved, we use generator expression
@@ -592,6 +598,8 @@  class addset(abstractsmartset):
     def __nonzero__(self):
         return bool(self._r1) or bool(self._r2)
 
+    __bool__ = __nonzero__
+
     @util.propertycache
     def _list(self):
         if not self._genlist:
@@ -752,6 +760,8 @@  class generatorset(abstractsmartset):
             return True
         return False
 
+    __bool__ = __nonzero__
+
     def __contains__(self, x):
         if x in self._cache:
             return self._cache[x]
@@ -970,6 +980,8 @@  class spanset(abstractsmartset):
             return True
         return False
 
+    __bool__ = __nonzero__
+
     def __len__(self):
         if not self._hiddenrevs:
             return abs(self._end - self._start)