Python class's init function takes instance of own class as default parameter

Solution 1:

You should do this:

class Node:
    def __init__(self, name, visited=False, distance=math.inf, path=None):
        self.name = name
        self.visited = visited
        self.distance = distance
        if path is None:
            self.path = Node('-', path="default-path")
        else:
            self.path = path

This is the idiom you should be following with mutable default arguments to begin with.

However, you need the default to have a path, or it will recurse without stopping.