Greg Ewing wrote: > Guido van Rossum wrote: >> try: >> hash(x) >> except TypeError: >> # apparently x is not hashable >> >> then you're also swallowing any type errors in the computation of a >> legitimate hash function. > > Maybe it would help if there were a specific exception, > such as NotHashableError, that hash functions were > expected to raise in this situation instead of a > generic TypeError. I was going to suggest this, but then I realized that what is really desirable is a check for hashability. But since hashability is a deep property, it is difficult to check for.. seems like an very specific exception type would be a simple solution. FYI, I appreciate that swallowing all TypeErrors is bad form, so it would be nice if it was possible to differentiate ;-) Some brief googling on the subject yield a discussion on py3k about this very subject. http://mail.python.org/pipermail/python-3000/2006-July/002697.html Guido wrote: > Personally, I'm not sure this problem needs solving; I don't recall > ever needing to know whether something is hashable. So perhaps it's of > purely theoretical importance? That would suit me fine given the above > dilemma... > > --Guido -- Scott Dial scott at scottdial.com scodial at indiana.edu
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