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.
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com