comparison mercurial/manifest.py @ 30331: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 f65faa4422c8
children b0ca939414ea
comparison
equal deleted inserted replaced
30330:a2f2f694dce9 30331:b19291e5d506
420 return self._lm[key] 420 return self._lm[key]
421 421
422 def __len__(self): 422 def __len__(self):
423 return len(self._lm) 423 return len(self._lm)
424 424
425 def __nonzero__(self):
426 # nonzero is covered by the __len__ function, but implementing it here
427 # makes it easier for extensions to override.
428 return len(self._lm) != 0
429
425 def __setitem__(self, key, node): 430 def __setitem__(self, key, node):
426 self._lm[key] = node, self.flags(key, '') 431 self._lm[key] = node, self.flags(key, '')
427 432
428 def __contains__(self, key): 433 def __contains__(self, key):
429 return key in self._lm 434 return key in self._lm