Aaron DeVore wrote:
> I'm writing a class/type that will be inserted into a list. After it
> is inserted the developer should be able to call
> a_list.index(my_type_instance) and get the my_type_instance index by
> *identity*, not by a call to my_type.__eq__. I have a my_type.__eq__
> function but it doesn't give the correct behavior. Which behavior does
> Cython use?

Cython lists are Python lists, so this should behave in the same way as 
in Python. If something is not working it would help with a code small 
example.

I.e. to do what you describe you should either not implement __eq__ at 
all, or have it return "self is other".

More details would help here (i.e. a working example of what you are 
trying to do and how it works in Python).

If you are trying to do something which cannot be done in Python then 
the answer is no, I suppose. You could consider writing a wrapper like this:

class IdWrapper:
     def __init__(self, x): self.x = x
     def __eq__(self, other): return self.x is other.x

and only insert objects through their wrapper...

-- 
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to