class_docstr: Do a pre-order traversal of a tree.
  
  This iterator recursively yields nodes that it has visited in a pre-order
  fashion. That is, it yields the current node then descends through the
  tree breadth-first to yield all of a node's children's pre-order
  traversal.
  
  
  For an expression, the order of the traversal depends on the order of
  .args, which in many cases can be arbitrary.
  
  Parameters
  ==========
  node : SymPy expression
      The expression to traverse.
  keys : (default None) sort key(s)
      The key(s) used to sort args of Basic objects. When None, args of Basic
      objects are processed in arbitrary order. If key is defined, it will
      be passed along to ordered() as the only key(s) to use to sort the
      arguments; if ``key`` is simply True then the default keys of ordered
      will be used.
  
  Yields
  ======
  subtree : SymPy expression
      All of the subtrees in the tree.
  
  Examples
  ========
  
  >>> from sympy import preorder_traversal, symbols
  >>> x, y, z = symbols('x y z')
  
  The nodes are returned in the order that they are encountered unless key
  is given; simply passing key=True will guarantee that the traversal is
  unique.
  
  >>> list(preorder_traversal((x + y)*z, keys=None)) # doctest: +SKIP
  [z*(x + y), z, x + y, y, x]
  >>> list(preorder_traversal((x + y)*z, keys=True))
  [z*(x + y), z, x + y, x, y]
code: def _preorder_traversal(self, node, keys):
      yield node
      if self._skip_flag:
          self._skip_flag = False
          return
      if isinstance(node, Basic):
          if not keys and hasattr(node, "_argset"):
              # LatticeOp keeps args as a set. We should use this if we
              # don't care about the order, to prevent unnecessary sorting.
              args = node._argset
          else:
              args = node.args
          if keys:
              if keys != True:
                  args = ordered(args, keys, default=False)
              else:
                  args = ordered(args)
          for arg in args:
              yield from self._preorder_traversal(arg, keys)
      elif iterable(node):
          for item in node:
              yield from self._preorder_traversal(item, keys)
  
file_path: sympy/sympy/core/traversal.py
imports: from .basic import Basic
  from .sorting import ordered
  from .sympify import sympify
  from sympy.utilities.iterables import iterable
label_desc: Use image node_id 2 for calling the preorder_traversal obj's underlying member method code with example usage: obj._preorder_traversal(node, keys) without return types