[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] BUG? rect __eq__



Hi,

I've been going through the doc comments and found this one about the
Rect __eq__ method.

I've added a unittest for the rect __eq__ behaviour.

Could this behaviour be improved at all?


"""WARNING: The Rect class has overridden some of the comparison methods of an object. One problem that occurs because of this is, if you have a list with multiple instances of a Rect WITH THE SAME RECTANGLE VALUES and you want to remove one, the wrong instance may be removed from the list.

This was a trouble for me when I subclassed Rect for my own object
type with extended information. I corrected it by restoring __eq__ to
it's basic definition. (comparing object identifiers)

class foo (pygame.Rect):
   def __eq__(self,other):
       return id(self) == id(other);
"""