Guido van Rossum wrote:
> On 7/26/06, Nick Coghlan <[EMAIL PROTECTED]> wrote:
>> class Unhashable(object):
>> __hash__ = Undefined
>
> Simpler: set it to None. That could be a convention.
>
And someone else pointed out that this could still be a trigger for NULL'ing
out slots at the C level, since None is a compiler-enforced singleton.
A direct check for callability/hashability/whateverability gets more verbose
though:
getattr(obj, "__hash__", None) is not None
The upside is that it would be simple to embody the convention in a couple of
functions:
def getslotattr(obj, slotname):
attr = getattr(obj, slotname)
if attr is None:
raise AttributeError("meaningful error message")
return attr
def hasslotattr(obj, slotname):
return getattr(obj, slotname, None) is not None
Cheers,
Nick.
--
Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com