r"""Traverse the given expression structure, returning an iterator. Traversal is configured to be breadth-first. The central API feature used by the :func:`.visitors.iterate` function is the :meth:`_expression.ClauseElement.get_children` method of :class:`_expression.ClauseElem
(
obj: Optional[ExternallyTraversible],
opts: Mapping[str, Any] = util.EMPTY_DICT,
)
| 804 | |
| 805 | |
| 806 | def iterate( |
| 807 | obj: Optional[ExternallyTraversible], |
| 808 | opts: Mapping[str, Any] = util.EMPTY_DICT, |
| 809 | ) -> Iterator[ExternallyTraversible]: |
| 810 | r"""Traverse the given expression structure, returning an iterator. |
| 811 | |
| 812 | Traversal is configured to be breadth-first. |
| 813 | |
| 814 | The central API feature used by the :func:`.visitors.iterate` |
| 815 | function is the |
| 816 | :meth:`_expression.ClauseElement.get_children` method of |
| 817 | :class:`_expression.ClauseElement` objects. This method should return all |
| 818 | the :class:`_expression.ClauseElement` objects which are associated with a |
| 819 | particular :class:`_expression.ClauseElement` object. For example, a |
| 820 | :class:`.Case` structure will refer to a series of |
| 821 | :class:`_expression.ColumnElement` objects within its "whens" and "else\_" |
| 822 | member variables. |
| 823 | |
| 824 | :param obj: :class:`_expression.ClauseElement` structure to be traversed |
| 825 | |
| 826 | :param opts: dictionary of iteration options. This dictionary is usually |
| 827 | empty in modern usage. |
| 828 | |
| 829 | """ |
| 830 | if obj is None: |
| 831 | return |
| 832 | |
| 833 | yield obj |
| 834 | children = obj.get_children(**opts) |
| 835 | |
| 836 | if not children: |
| 837 | return |
| 838 | |
| 839 | stack = deque([children]) |
| 840 | while stack: |
| 841 | t_iterator = stack.popleft() |
| 842 | for t in t_iterator: |
| 843 | yield t |
| 844 | stack.append(t.get_children(**opts)) |
| 845 | |
| 846 | |
| 847 | @overload |
no test coverage detected