[Barry] >>Would it be better if object.__hash__() raised a NotImplementedError? [Guido] > It can't -- it's type.__hash__(object). If I understand Barry's suggestion correctly, he means to keep object.__hash__, but have it raise a specific, meaningful error instead of making a potentially incorrect assumption as it does now. E.g. (not real code, since this would behave differently in Py 2.3.3) >>> class Works(object): pass >>> class Breaks(object): ... def __cmp__(): return 0 # All instances are created equal! >>> work = Works() >>> break = Breaks() >>> hash(work) 45632543 >>> hash(break) Traceback (most recent call last): <Traceback info> NotImplementedError: Must explicitly define __hash__ for non-default comparisons hash(work) is fine, since there is no __cmp__ or __eq__ override in Works, and hence object.__hash__ never gets called. hash(break) raises the exception because of the existence of the (rather useless) __cmp__ function in the Breaks class. Cheers, Nick. -- Nick Coghlan | Brisbane, Australia Email: ncoghlan at email.com | Mobile: +61 409 573 268
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4