fagus.iterators module

This module contains iterator-classes that are used to iterate over Fagus-objects

class fagus.iterators.FilteredIterator(obj: Collection[Any], filter_value: bool, filter_: Fil, filter_index: int = 0)

Bases: object

Iterator class that gives keys and values for any Collection (use optimal_iterator() to initialize it)

static optimal_iterator(obj: Collection[Any], filter_value: bool = False, filter_: Optional['Fil'] = None, filter_index: int = 0) Iterator[Any]

This method returns the simplest possible Iterator to loop through a given object.

If no filter is present, either items or enumerate are called to loop through the keys, for sets … is put as key for each value (as sets have no meaningful keys). If you additionally need filtering, this class is initialized to support iteration on only the keys and values that pass the filter

__init__(obj: Collection[Any], filter_value: bool, filter_: Fil, filter_index: int = 0) None
__iter__() FilteredIterator
__next__() Any
__dict__ = mappingproxy({'__module__': 'fagus.iterators', '__doc__': 'Iterator class that gives keys and values for any Collection (use optimal_iterator() to initialize it)', 'optimal_iterator': <staticmethod(<function FilteredIterator.optimal_iterator>)>, '__init__': <function FilteredIterator.__init__>, '__iter__': <function FilteredIterator.__iter__>, '__next__': <function FilteredIterator.__next__>, '__dict__': <attribute '__dict__' of 'FilteredIterator' objects>, '__weakref__': <attribute '__weakref__' of 'FilteredIterator' objects>, '__annotations__': {'match_key': 'Callable[[Any, int, Any], Tuple[bool, Optional[KFil], int]]'}})
__module__ = 'fagus.iterators'
__weakref__

list of weak references to the object (if defined)

class fagus.iterators.FagusIterator(obj: Fagus, max_depth: int = 9223372036854775807, filter_: Optional['Fil'] = None, fagus: bool = False, iter_fill: Any = <class 'fagus.utils._None'>, select: Optional[Union[int, Iterable[Any]]] = None, iter_nodes: bool = False, copy: bool = False, filter_ends: bool = False)

Bases: object

Iterator-class for Fagus to facilitate the complex iteration with filtering etc. in the tree-object

Internal - use Fagus.iter() to use this iterator on your object

__init__(obj: Fagus, max_depth: int = 9223372036854775807, filter_: Optional['Fil'] = None, fagus: bool = False, iter_fill: Any = <class 'fagus.utils._None'>, select: Optional[Union[int, Iterable[Any]]] = None, iter_nodes: bool = False, copy: bool = False, filter_ends: bool = False) None

Internal function. Recursively iterates through Fagus-object

Initiate this iterator through Fagus.iter(), there the parameters are discussed as well.

__dict__ = mappingproxy({'__module__': 'fagus.iterators', '__doc__': 'Iterator-class for Fagus to facilitate the complex iteration with filtering etc. in the tree-object\n\n    Internal - use Fagus.iter() to use this iterator on your object', '__init__': <function FagusIterator.__init__>, '__iter__': <function FagusIterator.__iter__>, '__next__': <function FagusIterator.__next__>, 'skip': <function FagusIterator.skip>, '__dict__': <attribute '__dict__' of 'FagusIterator' objects>, '__weakref__': <attribute '__weakref__' of 'FagusIterator' objects>, '__annotations__': {}})
__iter__() FagusIterator
__module__ = 'fagus.iterators'
__weakref__

list of weak references to the object (if defined)

__next__() Any
skip(level: int, copy: bool = False) Any

Skip the remaining iterations of a node at a given level if you’re done handling it

Parameters:
  • level (int) – which node to skip. Level 0 is the root node, the next node is level 1 etc.

  • copy (bool) – Whether to skip a copy of the node. Can be useful when the tree is modified during iteration

Returns:

The node that was skipped