Mutating state and then recursing makes me a little nervous. I would be more confident that this was correct if you created a new object for path, e.g.,

    key = path[0]
    path = path[1:]