Question: I'd like to create a generalized `__eq__()` method for the following Class. Basically I'd like to be able to add another property (`nick`) without having to change `__eq__()`

I imagine I can do this somehow by iterating over `dir()` but I wonder if there is a way to create a comprehension that just delivers the properties.

```
 class Person:
     def __init__(self, first, last):
         self.first=first
         self.last=last

     @property
     def first(self):
         assert(self._first != None)
         return self._first
     @first.setter
     def first(self,fn):
         assert(isinstance(fn,str))
         self._first=fn

     @property
     def last(self):
         assert(self._last != None)
         return self._last
     @last.setter
     def last(self,ln):
         assert(isinstance(ln,str))
         self._last=ln
     @property
     def full(self):
         return f'{self.first} {self.last}'

     def __eq__(self, other):
         return self.first==other.first and self.last==other.last

 p = Person('Raymond', 'Salemi')
 p2= Person('Ray', 'Salemi')

```

Answer: 
You could use `__dict__` to check if everything is the same, which scales for all attributes:

If the objects are not matching types, I simply return `False`.

```
class Person:
    def __init__(self, first, last, nick):
        self.first = first
        self.last = last
        self.nick = nick

    def __eq__(self, other):
        return self.__dict__ == other.__dict__  if type(self) == type(other) else False

>>> p = Person('Ray', 'Salemi', 'Ray')
>>> p2= Person('Ray', 'Salemi', 'Ray')
>>> p3 = Person('Jared', 'Salemi', 'Jarbear')

>>> p == p2
True
>>> p3 == p2
False
>>> p == 1
False

```
you can try to do this, it will also work if you want eq inside dict and set

```
def __eq__(self, other):
    """Overrides the default implementation"""
    if isinstance(self, other.__class__):
        return self.__hash__() == other.__hash__()

    return NotImplemented

def __hash__(self):
    """Overrides the default implementation,
       and set which fieds to use for hash generation
    """
    __make_hash = [
         self.first
    ]
    return hash(tuple(sorted(list(filter(None, __make_hash)))))

```