Unfortunately, there is no way (that I know of) to construct such an object. Consider:
>>> class Wildcard(object):
... def __eq__(self, other):
... return True
...
>>> w = Wildcard()
>>> w == 10
True
>>> 10 == w
True
>>> class Joker(object):
... def __eq__(self, other):
... return False
...
>>> j = Joker()
>>> w == j
True
>>> j == w
False
There is no reason for w
(a Wildcard
) to take precedence over j
(a Joker
) in this scenario.
Now, you might be wondering why this works for strings and ints -- It's because if the class's test returns the singleton NotImplemented
, then the test is delegated from the first argument to the second:
>>> class Foo(object):
... def __eq__(self, other):
... if isinstance(other, Wildcard):
... return NotImplemented
... else:
... return False
...
>>> f = Foo()
>>>
>>> f == 1
False
>>> f == Foo()
False
>>> f == w
True