codekingpro/portable-devtools
114k
1"""Private typing utilities for LangGraph."""2 3from __future__ import annotations4 5from dataclasses import Field6from typing import Any, ClassVar, Protocol, TypeAlias7 8from pydantic import BaseModel9from typing_extensions import TypedDict10 11 12class TypedDictLikeV1(Protocol):13 """Protocol to represent types that behave like TypedDicts14 15 Version 1: using `ClassVar` for keys."""16 17 __required_keys__: ClassVar[frozenset[str]]18 __optional_keys__: ClassVar[frozenset[str]]19 20 21class TypedDictLikeV2(Protocol):22 """Protocol to represent types that behave like TypedDicts23 24 Version 2: not using `ClassVar` for keys."""25 26 __required_keys__: frozenset[str]27 __optional_keys__: frozenset[str]28 29 30class DataclassLike(Protocol):31 """Protocol to represent types that behave like dataclasses.32 33 Inspired by the private _DataclassT from dataclasses that uses a similar protocol as a bound."""34 35 __dataclass_fields__: ClassVar[dict[str, Field[Any]]]36 37 38StateLike: TypeAlias = TypedDictLikeV1 | TypedDictLikeV2 | DataclassLike | BaseModel39"""Type alias for state-like types.40 41It can either be a `TypedDict`, `dataclass`, or Pydantic `BaseModel`.42Note: we cannot use either `TypedDict` or `dataclass` directly due to limitations in type checking.43"""44 45MISSING = object()46"""Unset sentinel value."""47 48 49class DeprecatedKwargs(TypedDict):50 """TypedDict to use for extra keyword arguments, enabling type checking warnings for deprecated arguments."""51 52 53EMPTY_SEQ: tuple[str, ...] = tuple()54"""An empty sequence of strings."""55 