Pre-PEP: __hashable__
Delaney, Timothy
tdelaney at avaya.com
Tue Dec 10 21:53:42 EST 2002
More information about the Python-list mailing list
Tue Dec 10 21:53:42 EST 2002
- Previous message (by thread): Pre-PEP: __hashable__
- Next message (by thread): Pre-PEP: __hashable__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> From: Delaney, Timothy [mailto:tdelaney at avaya.com] > Possibly a more reasonable implementation would be: def hashable (obj): try: obj.__hash__() return obj except AttributeError: try: return obj.__hashable__() except AttributeError: raise TypeError('unhashable type') def hash (obj): try: return obj.__hash__() except AttributeError: try: return hashable(obj).__hash__() except AttributeError: raise TypeError('unhashable type') This would mean in each case that __hash__() is only called the once. Since __hashable__ is specified to return an object which is hashable anything which fails to do so is broken. Tim Delaney
- Previous message (by thread): Pre-PEP: __hashable__
- Next message (by thread): Pre-PEP: __hashable__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list