# HG changeset patch # User Durham Goode # Date 2016-11-04 00:31:14 # Node ID b19291e5d506238acd84f5890da7adadd8167e82 # Parent a2f2f694dce9f38363ae0c9d66e3fb3247fcd396 manifest: add __nonzero__ method This adds a __nonzero__ method to manifestdict. This isn't strictly necessary in the vanilla Mercurial implementation, since Python will handle nonzero checks by using __len__, but having it implemented here makes it easier for alternative implementations to implement __nonzero__ and have them be plug-n-play with the normal implementation. diff --git a/mercurial/manifest.py b/mercurial/manifest.py --- a/mercurial/manifest.py +++ b/mercurial/manifest.py @@ -422,6 +422,11 @@ class manifestdict(object): def __len__(self): return len(self._lm) + def __nonzero__(self): + # nonzero is covered by the __len__ function, but implementing it here + # makes it easier for extensions to override. + return len(self._lm) != 0 + def __setitem__(self, key, node): self._lm[key] = node, self.flags(key, '')