Table of Contents

Class: HashAndCompare ./src/peak/util/hashcmp.py

Mixin that allows hash and cmp operations on a delegate value

model.Immutable, model.Struct, and model.Enumeration all use this mixin so that their instances can be hashed and compared according to a delegate value. For enumerations, it's the "value" of the enumeration, and for the others it's a tuple of attribute values.

You only need to use this mixin if you aren't using one of the immutable element base classes such as model.Immutable or model.Struct, but you want to be able to have your instances implement __hash__, __cmp__, and __nonzero__ based on a delegate value in the same way.

To use this mixin, just add it to your base class list, and ensure that your _hashAndCompare attribute is always the desired delegate value. If your instances are to be used as dictionary keys, the value of the _hashAndCompare attribute must be hashable, immutable, and must never vary. That is, every access of the _hashAndCompare value should return the same or an equivalent object.

Base Classes   
object
Methods   
__cmp__
__hash__
__nonzero__
  __cmp__ 
__cmp__ ( self,  other )

  __hash__ 
__hash__ ( self )

  __nonzero__ 
__nonzero__ ( self )


Table of Contents

This document was automatically generated on Mon Apr 15 01:11:04 2024 by HappyDoc version 2.1