[Python-Dev] For Python 3k, drop default/implicit hash, and comparison
Technical Support of Intercable Co
support at intercable.ru
Tue Nov 8 08:59:42 CET 2005
Why 'identity' objects can't define:
def __getKey__(self):
return Key(self, id(self))
Then they would act as usually, while value object can define
def __getKey__(self):
return Key(self, self.i, self.j, self.a[1])
(Key is an abstraction to handle subclassing)
Of course, there should be a way to handle comparison off the class
ierarhy (i think)
Today one can write:
>>> class Boo(object):
def __init__(self,s=""):
self.s=s
def __hash__(self):
return hash(self.s)
def __cmp__(self,other):
if type(self)==type(other):
return cmp(self.s,other.s)
if type(other)==str:
return cmp(self.s,other)
>>> a={}
>>> a['s']=1
>>> a[Boo('s')]
1
>>> a[Boo('z')]=2
>>> a['z']
2
It is confused and hardly usefull, but possible.
Excuse my english.
More information about the Python-Dev
mailing list