astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- asdf v »
- Developer API »
- walk_and_modify

# walk_and_modify

asdf.treeutil.walk_and_modify(top, callback, ignore_implicit_conversion=False, postorder=True, _context=None)

  Modify a tree by walking it with a callback function. It also has the effect of doing a deep copy.

  Parameters:
    top object

      The root of the tree. May be a dict, list or other Python object.

    callback callable

      A function to call at each node in the tree. It takes either one or two arguments:

      - an instance from the tree

      - a json id (optional)

      It may return a different instance in order to modify the tree. If the singleton instance `_RemoveNode` is returned, the node will be removed from the tree.

      The json id is the context under which any relative URLs should be resolved. It may be `None` if no ids are in the file

      The tree is traversed depth-first, with order specified by the `postorder` argument.

    postorder bool

      Determines the order in which the callable is invoked on nodes of the tree. If `True`, the callable will be invoked on children before their parents. If `False`, the callable is invoked on the parents first. Defaults to `True`.

    ignore_implicit_conversion bool

      Controls whether warnings should be issued when implicitly converting a given type instance in the tree into a serializable object. The primary case for this is currently `namedtuple`.

      Defaults to `False`.

  Returns:
    tree object

      The modified tree.