> -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of [email protected] > Sent: 08 January 2009 19:11 > To: [email protected] > Subject: [sqlalchemy] Re: SQLAlchemy 0.5 Released > > > On Thursday 08 January 2009 21:03:42 Michael Bayer wrote: > > On Jan 8, 2009, at 12:52 PM, [email protected] wrote: > > > instead of None, better do some empty method raising some error, > > > because in the current way the error comes up in not at all > > > obvious fashion, takes quite some head-scratching to find-out - > > > there's no mentioning of anything set() related there. > > > > __hash__ = None means no hash is defined. Its in the Python docs. > okay, have fun with > TypeError: 'NoneType' object is not callable >
http://docs.python.org/reference/datamodel.html#object.__hash__ implies that "__hash__ = None" only took on that special meaning in Python 2.6 In Python 2.5, I think you're probably supposed to explicitly raise a TypeError, but in Python 2.6 that would cause isinstance(obj, collections.Hashable) to give the wrong answer. Maybe you could do something like this: #-------------------------------------------------------------------- import sys if sys.version_info < (2, 6): def unhashable(self): raise TypeError('%s objects are not hashable' % type(self).__name__) else: unhashable = None def test(): print "Testing on Python version %s" % (sys.version_info,) class Dummy(object): __hash__ = unhashable dummy = Dummy() try: print "FAIL: hash(dummy) = %s" % hash(dummy) except TypeError, e: print "PASS: %s" % e if sys.version_info >= (2, 6): import collections if isinstance(dummy, collections.Hashable): print "FAIL: isinstance(dummy, collections.Hashable) -> True" else: print "PASS: isinstance(dummy, collections.Hashable) -> False" if __name__ == '__main__': test() #-------------------------------------------------------------------- That basic test seems to work on Python 2.4, 2.5 and 2.6. Simon --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
