Visitor/traversal interface and library functions.
Class | anon |
A map that creates new keys for missing key access. |
Class |
|
Base class for visitor objects which can traverse using the :func:`.visitors.cloned_traverse` function. |
Class |
|
No class docstring; 0/1 class variable, 2/4 methods documented |
Class |
|
Base class for visitor objects which can traverse externally using the :func:`.visitors.traverse` function. |
Class |
|
Define infrastructure for classes that perform internal traversals |
Class |
|
base for classes that have a "traverse internals" element, which defines all kinds of ways of traversing the elements of an object. |
Class |
|
Defines visitor symbols used for internal traversal. |
Class |
|
Base class for visitor objects which can traverse using the :func:`.visitors.replacement_traverse` function. |
Class |
|
Base class for visitable objects. |
Function | cloned |
Clone the given expression structure, allowing modifications by visitors for mutable objects. |
Function | iterate |
Traverse the given expression structure, returning an iterator. |
Function | replacement |
Clone the given expression structure, allowing element replacement by a given replacement function. |
Function | traverse |
Traverse and visit the given expression structure using the default iterator. |
Function | traverse |
Visit the given expression structure using the given iterator of objects. |
Class | _ |
Undocumented |
Class | _ |
Undocumented |
Class | _ |
Undocumented |
Class | _ |
Undocumented |
Function | _generate |
Undocumented |
Type Variable | _CE |
Undocumented |
Type Variable | _ET |
Undocumented |
Type Variable | _ |
Undocumented |
Type Alias | _ |
Undocumented |
Type Alias | _ |
a structure that defines how a HasTraverseInternals should be traversed. |
Literal[ None]
, opts: Mapping[ str, Any]
, visitors: Mapping[ str, _TraverseCallableType[ Any]]
):_ET
, opts: Mapping[ str, Any]
, visitors: Mapping[ str, _TraverseCallableType[ Any]]
) -> _ET
:Clone the given expression structure, allowing modifications by visitors for mutable objects. Traversal usage is the same as that of :func:`.visitors.traverse`. The visitor functions present in the ``visitors`` dictionary may also modify the internals of the given structure as the traversal proceeds. The :func:`.cloned_traverse` function does **not** provide objects that are part of the :class:`.Immutable` interface to the visit methods (this primarily includes :class:`.ColumnClause`, :class:`.Column`, :class:`.TableClause` and :class:`.Table` objects). As this traversal is only intended to allow in-place mutation of objects, :class:`.Immutable` objects are skipped. The :meth:`.Immutable._clone` method is still called on each object to allow for objects to replace themselves with a different object based on a clone of their sub-internals (e.g. a :class:`.ColumnClause` that clones its subquery to return a new :class:`.ColumnClause`). .. versionchanged:: 2.0 The :func:`.cloned_traverse` function omits objects that are part of the :class:`.Immutable` interface. The central API feature used by the :func:`.visitors.cloned_traverse` and :func:`.visitors.replacement_traverse` functions, in addition to the :meth:`_expression.ClauseElement.get_children` function that is used to achieve the iteration, is the :meth:`_expression.ClauseElement._copy_internals` method. For a :class:`_expression.ClauseElement` structure to support cloning and replacement traversals correctly, it needs to be able to pass a cloning function into its internal members in order to make copies of them. .. seealso:: :func:`.visitors.traverse` :func:`.visitors.replacement_traverse`
Optional[ ExternallyTraversible]
, opts: Mapping[ str, Any]
= util.EMPTY_DICT) -> Iterator[ ExternallyTraversible]
:
(source)
¶
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.ClauseElement` objects. This method should return all the :class:`_expression.ClauseElement` objects which are associated with a particular :class:`_expression.ClauseElement` object. For example, a :class:`.Case` structure will refer to a series of :class:`_expression.ColumnElement` objects within its "whens" and "else\_" member variables. :param obj: :class:`_expression.ClauseElement` structure to be traversed :param opts: dictionary of iteration options. This dictionary is usually empty in modern usage.
Literal[ None]
, opts: Mapping[ str, Any]
, replace: _TraverseTransformCallableType[ Any]
):_CE
, opts: Mapping[ str, Any]
, replace: _TraverseTransformCallableType[ Any]
) -> _CE
:ExternallyTraversible
, opts: Mapping[ str, Any]
, replace: _TraverseTransformCallableType[ Any]
) -> ExternallyTraversible
:Clone the given expression structure, allowing element replacement by a given replacement function. This function is very similar to the :func:`.visitors.cloned_traverse` function, except instead of being passed a dictionary of visitors, all elements are unconditionally passed into the given replace function. The replace function then has the option to return an entirely new object which will replace the one given. If it returns ``None``, then the object is kept in place. The difference in usage between :func:`.visitors.cloned_traverse` and :func:`.visitors.replacement_traverse` is that in the former case, an already-cloned object is passed to the visitor function, and the visitor function can then manipulate the internal state of the object. In the case of the latter, the visitor function should only return an entirely different object, or do nothing. The use case for :func:`.visitors.replacement_traverse` is that of replacing a FROM clause inside of a SQL structure with a different one, as is a common use case within the ORM.
Literal[ None]
, opts: Mapping[ str, Any]
, visitors: Mapping[ str, _TraverseCallableType[ Any]]
):ExternallyTraversible
, opts: Mapping[ str, Any]
, visitors: Mapping[ str, _TraverseCallableType[ Any]]
) -> ExternallyTraversible
:Traverse and visit the given expression structure using the default iterator. e.g.:: from sqlalchemy.sql import visitors stmt = select(some_table).where(some_table.c.foo == 'bar') def visit_bindparam(bind_param): print("found bound value: %s" % bind_param.value) visitors.traverse(stmt, {}, {"bindparam": visit_bindparam}) The iteration of objects uses the :func:`.visitors.iterate` function, which does a breadth-first traversal using a stack. :param obj: :class:`_expression.ClauseElement` structure to be traversed :param opts: dictionary of iteration options. This dictionary is usually empty in modern usage. :param visitors: dictionary of visit functions. The dictionary should have strings as keys, each of which would correspond to the ``__visit_name__`` of a particular kind of SQL expression object, and callable functions as values, each of which represents a visitor function for that kind of object.
Iterable[ ExternallyTraversible]
, obj: Literal[ None]
, visitors: Mapping[ str, _TraverseCallableType[ Any]]
):Iterable[ ExternallyTraversible]
, obj: ExternallyTraversible
, visitors: Mapping[ str, _TraverseCallableType[ Any]]
) -> ExternallyTraversible
:Visit the given expression structure using the given iterator of objects. :func:`.visitors.traverse_using` is usually called internally as the result of the :func:`.visitors.traverse` function. :param iterator: an iterable or sequence which will yield :class:`_expression.ClauseElement` structures; the iterator is assumed to be the product of the :func:`.visitors.iterate` function. :param obj: the :class:`_expression.ClauseElement` that was used as the target of the :func:`.iterate` function. :param visitors: dictionary of visit functions. See :func:`.traverse` for details on this dictionary. .. seealso:: :func:`.traverse`
a structure that defines how a HasTraverseInternals should be traversed. This structure consists of a list of (attributename, internaltraversal) tuples, where the "attributename" refers to the name of an attribute on an instance of the HasTraverseInternals object, and "internaltraversal" refers to an :class:`.InternalTraversal` enumeration symbol defining what kind of data this attribute stores, which indicates to the traverser how it should be handled.
Value |
|