Added a __hash__ function to Quantity class #29

wants to merge 1 commit into from

2 participants


This allows dictionaries to have Quantities as keys.

@rsenk330 rsenk330 Added a __hash__ function to Quantity.
This allows dictionaries to have Quantities as keys.
python-quantities member

I'm sorry, but you can't use mutable objects as dictionary keys, even if they have a hash. :

class UserString.MutableString([sequence])
This class is derived from the UserString above and redefines strings to be mutable. Mutable strings can’t be used as dictionary keys, because dictionaries require immutable objects as keys. The main intention of this class is to serve as an educational example for inheritance and necessity to remove (override) the hash() method in order to trap attempts to use a mutable object as dictionary key, which would be otherwise very error prone and hard to track down.

@ddale ddale closed this Dec 19, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment