Mercurial > hg-stable
changeset 30341:b19291e5d506
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.
author | Durham Goode <durham@fb.com> |
---|---|
date | Thu, 03 Nov 2016 17:31:14 -0700 |
parents | a2f2f694dce9 |
children | 318a24b52eeb |
files | mercurial/manifest.py |
diffstat | 1 files changed, 5 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/manifest.py Sun Nov 06 04:36:26 2016 +0530 +++ b/mercurial/manifest.py Thu Nov 03 17:31:14 2016 -0700 @@ -422,6 +422,11 @@ 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, '')