pyscript icon indicating copy to clipboard operation
pyscript copied to clipboard

using __eq__ in class doesn't seem to work

Open idogrf opened this issue 3 years ago • 0 comments

Hi,

I'm using some classes inside my pyscripts. I stumbled across a weird behavior when trying to define the __eq__ in one of my classes.

Here's a mockup class which reproduces the issue -

class A():
    def __init__(self, b):
        self.b = b
    
    def __eq__(self, other):
        return self.b == other

When I init a class obj, let's say -a = A(5), I always get True when trying to compare. So for example a == 3 gives True, a == 'cow' gives True.

Adding logging inside the __eq__ doesn't show anything so I believe that function isn't even being called.

I'm running all this on jupyter using the hass pyscript kernel Running the same on a normal python interpreter gives the expected resutls..

What am I missing here?

idogrf avatar May 15 '22 22:05 idogrf