Equal to Anything

S

Simon Brunning

For the purposes of a little test utility that we use, I need an
object that evaluates as equal to anything. (I realise that this is a
bad idea in some ways, breaking the equals/hashcode invariant and so
forth, but I'm hoping that I can get away with it in this case.) It
seems a simple enough task at first:
.... def __eq__(self, other):
.... return True
....
True

But...
False

I'm fairly sure that I know what is going on here - the left hand side
object is getting first stab at the equality test, and understandably,
it's saying "Nah". But is there anything that I can do about it?
 
D

Duncan Booth

Simon Brunning said:
I'm fairly sure that I know what is going on here - the left hand side
object is getting first stab at the equality test, and understandably,
it's saying "Nah". But is there anything that I can do about it?
Not in general, no. If you could, and someone else created a
NotEqualAnything class with the identical definition to EqualAnything
except it returns False, then which would win?

Sorry, but the left hand value wins unless it volunteers otherwise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top