Question

Why do I get " return self.__hash__() RuntimeError: maximum recursion depth exceeded" when I use the default hash method?

This causes the error:

def __hash__(self):
    return self.__hash__()

This works:

def __hash__(self):
    return self.name.__hash__()
Was it helpful?

Solution

Of course you are getting into infinite recursion by calling method from itself:

def method_name(self):
    return self.method_name()

You might wanted to call method of the base class?

def __hash__(self):
    return super(ClassName, self).__hash__()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top