py3: 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__.
--- a/contrib/check-code.py Mon Mar 13 21:58:43 2017 -0700
+++ b/contrib/check-code.py Mon Mar 13 12:40:14 2017 -0700
@@ -318,7 +318,7 @@
'legacy exception syntax; use "as" instead of ","'),
(r':\n( )*( ){1,3}[^ ]', "must indent 4 spaces"),
(r'release\(.*wlock, .*lock\)', "wrong lock release order"),
- (r'\b__bool__\b', "__bool__ should be __nonzero__ in Python 2"),
+ (r'\bdef\s+__bool__\b', "__bool__ should be __nonzero__ in Python 2"),
(r'os\.path\.join\(.*, *(""|\'\')\)',
"use pathutil.normasprefix(path) instead of os.path.join(path, '')"),
(r'\s0[0-7]+\b', 'legacy octal syntax; use "0o" prefix instead of "0"'),
--- a/contrib/perf.py Mon Mar 13 21:58:43 2017 -0700
+++ b/contrib/perf.py Mon Mar 13 12:40:14 2017 -0700
@@ -165,6 +165,7 @@
self.hexfunc = node.short
def __nonzero__(self):
return False
+ __bool__ = __nonzero__
def startitem(self):
pass
def data(self, **data):
--- a/mercurial/ancestor.py Mon Mar 13 21:58:43 2017 -0700
+++ b/mercurial/ancestor.py Mon Mar 13 12:40:14 2017 -0700
@@ -296,6 +296,8 @@
except StopIteration:
return False
+ __bool__ = __nonzero__
+
def __iter__(self):
"""Generate the ancestors of _initrevs in reverse topological order.
--- a/mercurial/bundle2.py Mon Mar 13 21:58:43 2017 -0700
+++ b/mercurial/bundle2.py Mon Mar 13 12:40:14 2017 -0700
@@ -271,6 +271,8 @@
def __nonzero__(self):
return bool(self._sequences)
+ __bool__ = __nonzero__
+
class bundleoperation(object):
"""an object that represents a single bundling process
--- a/mercurial/context.py Mon Mar 13 21:58:43 2017 -0700
+++ b/mercurial/context.py Mon Mar 13 12:40:14 2017 -0700
@@ -534,6 +534,8 @@
def __nonzero__(self):
return self._rev != nullrev
+ __bool__ = __nonzero__
+
@propertycache
def _changeset(self):
return self._repo.changelog.changelogrevision(self.rev())
@@ -722,6 +724,8 @@
# file is missing
return False
+ __bool__ = __nonzero__
+
def __str__(self):
try:
return "%s@%s" % (self.path(), self._changectx)
@@ -1238,6 +1242,8 @@
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
@@ -1711,6 +1717,8 @@
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()
--- a/mercurial/hgweb/webutil.py Mon Mar 13 21:58:43 2017 -0700
+++ b/mercurial/hgweb/webutil.py Mon Mar 13 12:40:14 2017 -0700
@@ -72,6 +72,8 @@
"""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:
--- a/mercurial/localrepo.py Mon Mar 13 21:58:43 2017 -0700
+++ b/mercurial/localrepo.py Mon Mar 13 12:40:14 2017 -0700
@@ -585,6 +585,8 @@
def __nonzero__(self):
return True
+ __bool__ = __nonzero__
+
def __len__(self):
return len(self.changelog)
--- a/mercurial/manifest.py Mon Mar 13 21:58:43 2017 -0700
+++ b/mercurial/manifest.py Mon Mar 13 12:40:14 2017 -0700
@@ -431,6 +431,8 @@
# 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, '')
--- a/mercurial/obsolete.py Mon Mar 13 21:58:43 2017 -0700
+++ b/mercurial/obsolete.py Mon Mar 13 12:40:14 2017 -0700
@@ -552,6 +552,8 @@
pass
return bool(self._all)
+ __bool__ = __nonzero__
+
@property
def readonly(self):
"""True if marker creation is disabled
--- a/mercurial/smartset.py Mon Mar 13 21:58:43 2017 -0700
+++ b/mercurial/smartset.py Mon Mar 13 12:40:14 2017 -0700
@@ -40,6 +40,8 @@
"""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 @@
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 @@
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 @@
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 @@
return True
return False
+ __bool__ = __nonzero__
+
def __contains__(self, x):
if x in self._cache:
return self._cache[x]
@@ -970,6 +980,8 @@
return True
return False
+ __bool__ = __nonzero__
+
def __len__(self):
if not self._hiddenrevs:
return abs(self._end - self._start)