Issue1297986
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2005-09-21 17:55 by cybb20, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (4) | |||
---|---|---|---|
msg54619 - (view) | Author: ChristianJ (cybb20) | Date: 2005-09-21 17:55 | |
It is not easy to check if an object is hashable, ie hasattr(list(), '__hash__') -> True try: hash(list()) except TypeError: pass seems to be a possible way to see if an object is hashable, however it is not satisfiable that this information needs to be retrieved by using exception handling. My proposal: There should be a hashable(obj) function returning a bool object and additionally it would be nice to have something like ismutable(obj) function, possibly as built-in functions. Reason: callable() is a built-in function and returns information about an object whether it's callable or not, that is a basic info about this object. If an object is hashable or mutable is a state of an object that is also very important to know. |
|||
msg54620 - (view) | Author: Georg Brandl (georg.brandl) * | Date: 2005-09-22 06:27 | |
Logged In: YES user_id=1188172 > try: hash(list()) > except TypeError: pass > > seems to be a possible way to see if an object is > hashable, however it is not satisfiable that this > information needs to be retrieved by using exception > handling. Why? > My proposal: > There should be a hashable(obj) function returning a > bool object and additionally it would be nice to have > something like ismutable(obj) function, possibly as > built-in functions. How should "ismutable" be implemented? > Reason: > callable() is a built-in function and returns > information about an object whether it's callable or > not, that is a basic info about this object. > If an object is hashable or mutable is a state of an > object that is also very important to know. It's easier to ask for forgiveness than permission. Even callable() has been called a mistake. Just call it and see where you come. So, -1. |
|||
msg54621 - (view) | Author: Michael Hudson (mwh) | Date: 2005-09-22 08:16 | |
Logged In: YES user_id=6656 def ishashable(ob): try: hash(ob) return True except TypeError: return False is the only reasonable way to implement this function (incidentally, do you know how hasattr works?). I don't see the need for a builtin, but am not feeling bolshy enough to just close the tracker item. Maybe someone else does. |
|||
msg54622 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2005-09-22 09:20 | |
Logged In: YES user_id=80475 Adding a third -1 from me and closing the RFE. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:13 | admin | set | github: 42395 |
2005-09-21 17:55:31 | cybb20 | create |