delegates() should provide __eq__ and __ne__ operators.

Bug #331919 reported by Henning Eggers
6
Affects Status Importance Assigned to Milestone
lazr.delegates
Triaged
Wishlist
Unassigned

Bug Description

It would be very useful if delegates would add these to a class:

    def __eq__(self, other):
        return (self.context == other.context)

    def __ne__(self, other):
        return not (self == other)

Tags: tech-debt
Revision history for this message
Henning Eggers (henninge) wrote :

I changed the subject and description because the original was a misunderstanding with my reviewer.

description: updated
Revision history for this message
Curtis Hovey (sinzui) wrote :

I think this is right thing to do in most cases. I think it may need to try other.context or other. I expect delegated_bug to equal bug.

Changed in lazr.delegates:
importance: Undecided → Low
status: New → Triaged
Revision history for this message
Guilherme Salgado (salgado) wrote :

IIUC, this bug is only about making a delegated object compare equally to another delegated object (when both have the same context)?

I ask that because I've been tempted to make delegated objects compare equally to their raw counterpart (delegated_bug == bug), and I even implemented __eq__ and __ne__ for lazr.delegates, but before I submitted that for review I realized it would also be nice to have them be identical so that they could be used interchangeably as, let's say, keys in dictionaries. Also, some other changes were necessary to fool Storm into thinking that a delegated_bug was a Bug, so that we could pass in delegated objects to storm. I kept encountering problems as I progressed, and at one point I finally realized it certainly wasn't a good idea to promote delegated objects to be used interchangeably with raw ones, so I backed out my changes and went with a completely different approach.

So, to summarize, I think it's a good idea to implement __eq__ and __ne__ as in the bug's description, but I'm not sure making delegated_bug compares equally to bug is a good idea.

Revision history for this message
Aaron Bentley (abentley) wrote :

I don't think this is a good idea, because it assumes that the context is the only relevant consideration for equality testing. There may be other relevant variables, so explicit is better than implicit.

Also, the example shown in the description does not even ensure that the two items being compared are of the same type.

Curtis Hovey (sinzui)
tags: added: tech-debt
Barry Warsaw (barry)
Changed in lazr.delegates:
importance: Low → Wishlist
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.