Home / File/ iter.py — langchain Source File

iter.py — langchain Source File

Architecture documentation for iter.py, a python file in the langchain codebase. 6 imports, 0 dependents.

File python CoreAbstractions RunnableInterface 6 imports 2 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  b289db43_7cd8_e404_08a4_ad932b851c13["iter.py"]
  efd68536_3a44_76e4_ec2a_0ec171774703["collections"]
  b289db43_7cd8_e404_08a4_ad932b851c13 --> efd68536_3a44_76e4_ec2a_0ec171774703
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  b289db43_7cd8_e404_08a4_ad932b851c13 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  69e1d8cc_6173_dcd0_bfdf_2132d8e1ce56["contextlib"]
  b289db43_7cd8_e404_08a4_ad932b851c13 --> 69e1d8cc_6173_dcd0_bfdf_2132d8e1ce56
  436f77bc_653d_0edb_555c_c2679d5a59ac["itertools"]
  b289db43_7cd8_e404_08a4_ad932b851c13 --> 436f77bc_653d_0edb_555c_c2679d5a59ac
  05bcd40b_a309_8a05_c2c6_59e32e113cf5["types"]
  b289db43_7cd8_e404_08a4_ad932b851c13 --> 05bcd40b_a309_8a05_c2c6_59e32e113cf5
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  b289db43_7cd8_e404_08a4_ad932b851c13 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  style b289db43_7cd8_e404_08a4_ad932b851c13 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Utilities for working with iterators."""

from collections import deque
from collections.abc import Generator, Iterable, Iterator
from contextlib import AbstractContextManager
from itertools import islice
from types import TracebackType
from typing import (
    Any,
    Generic,
    Literal,
    TypeVar,
    overload,
)

T = TypeVar("T")


class NoLock:
    """Dummy lock that provides the proper interface but no protection."""

    def __enter__(self) -> None:
        """Do nothing."""

    def __exit__(
        self,
        exc_type: type[BaseException] | None,
        exc_val: BaseException | None,
        exc_tb: TracebackType | None,
    ) -> Literal[False]:
        """Return False (exception not suppressed)."""
        return False


def tee_peer(
    iterator: Iterator[T],
    # the buffer specific to this peer
    buffer: deque[T],
    # the buffers of all peers, including our own
    peers: list[deque[T]],
    lock: AbstractContextManager[Any],
) -> Generator[T, None, None]:
    """An individual iterator of a `.tee`.

    This function is a generator that yields items from the shared iterator `iterator`.
    It buffers items until the least advanced iterator has yielded them as well. The
    buffer is shared with all other peers.

    Args:
        iterator: The shared iterator.
        buffer: The buffer for this peer.
        peers: The buffers of all peers.
        lock: The lock to synchronise access to the shared buffers.

    Yields:
        The next item from the shared iterator.
    """
    try:
        while True:
            if not buffer:
// ... (164 more lines)

Subdomains

Classes

Dependencies

  • collections
  • collections.abc
  • contextlib
  • itertools
  • types
  • typing

Frequently Asked Questions

What does iter.py do?
iter.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in iter.py?
iter.py defines 2 function(s): batch_iterate, tee_peer.
What does iter.py depend on?
iter.py imports 6 module(s): collections, collections.abc, contextlib, itertools, types, typing.
Where is iter.py in the architecture?
iter.py is located at libs/core/langchain_core/utils/iter.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/core/langchain_core/utils).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free