Skip to content

semlib.find

find async

find[T](
    iterable: Iterable[T],
    /,
    *,
    by: str | None = None,
    to_str: Callable[[T], str] | None = None,
    template: str | Callable[[T], str] | None = None,
    negate: bool = False,
    model: str | None = None,
    max_concurrency: int | None = None,
) -> T | None

Standalone version of find.

Source code in src/semlib/find.py
async def find[T](
    iterable: Iterable[T],
    /,
    *,
    by: str | None = None,
    to_str: Callable[[T], str] | None = None,
    template: str | Callable[[T], str] | None = None,
    negate: bool = False,
    model: str | None = None,
    max_concurrency: int | None = None,
) -> T | None:
    """Standalone version of [find][semlib.find.Find.find]."""
    finder = Find(model=model, max_concurrency=max_concurrency)
    result = await finder.find(iterable, by=by, to_str=to_str, template=template, negate=negate)
    # binding to intermediate variable coro to avoid mypy bug, see https://github.com/python/mypy/issues/19716 and
    # https://github.com/python/mypy/pull/19767 (fixed now, but not shipped yet)
    return result  # noqa: RET504

find_sync

find_sync[T](
    iterable: Iterable[T],
    /,
    *,
    by: str | None = None,
    to_str: Callable[[T], str] | None = None,
    template: str | Callable[[T], str] | None = None,
    negate: bool = False,
    model: str | None = None,
    max_concurrency: int | None = None,
) -> T | None

Standalone synchronous version of find.

Source code in src/semlib/find.py
def find_sync[T](
    iterable: Iterable[T],
    /,
    *,
    by: str | None = None,
    to_str: Callable[[T], str] | None = None,
    template: str | Callable[[T], str] | None = None,
    negate: bool = False,
    model: str | None = None,
    max_concurrency: int | None = None,
) -> T | None:
    """Standalone synchronous version of [find][semlib.find.Find.find]."""
    finder = Find(model=model, max_concurrency=max_concurrency)
    coro = finder.find(iterable, by=by, to_str=to_str, template=template, negate=negate)
    # binding to intermediate variable coro to avoid mypy bug, see https://github.com/python/mypy/issues/19716 and
    # https://github.com/python/mypy/pull/19767 (fixed now, but not shipped yet)
    return asyncio.run(coro)

:::