def flatten(self, root):
        " flatten the root object and all it's references "

        self.root = root
        self.queue( self.root )
        while self.todo:
            item = self.todo.pop(0)
            if isinstance(item, list):
                self.flat_list(item)
            if isinstance(item, set):
                self.flat_set(item)
            if isinstance(item, dict):
                self.flat_dict(item)
            if hasattr(item, "__dict__"):
                self.flat_attrs(item)
            # tuple ? other immutables ? __set/getstate__ ?

        # flush items (do not pickle them)
        self.items = {}
 flatten the root object and all it's references 
recipes/Python/302535_Handling_Deeply_NestedRecursive/recipe-302535.py