mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-26 01:22:24 +02:00
64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
import re
|
|
from typing import Union
|
|
|
|
|
|
class AnyStr(str):
|
|
def __init__(self, prefix: Union[str, re.Pattern] = "") -> None:
|
|
super().__init__()
|
|
self.prefix = prefix
|
|
|
|
def __eq__(self, other: object) -> bool:
|
|
return isinstance(other, str) and (
|
|
other.startswith(self.prefix)
|
|
if isinstance(self.prefix, str)
|
|
else self.prefix.match(other)
|
|
)
|
|
|
|
def __hash__(self) -> int:
|
|
return hash((str(self), self.prefix))
|
|
|
|
|
|
class AnyDict(dict):
|
|
def __init__(self, *args, **kwargs) -> None:
|
|
super().__init__(*args, **kwargs)
|
|
|
|
def __eq__(self, other: object) -> bool:
|
|
if not self and isinstance(other, dict):
|
|
return True
|
|
if not isinstance(other, dict) or len(self) != len(other):
|
|
return False
|
|
for k, v in self.items():
|
|
if kk := next((kk for kk in other if kk == k), None):
|
|
if v == other[kk]:
|
|
continue
|
|
else:
|
|
return False
|
|
else:
|
|
return True
|
|
|
|
|
|
class AnyList(list):
|
|
def __init__(self, *args, **kwargs) -> None:
|
|
super().__init__(*args, **kwargs)
|
|
|
|
def __eq__(self, other: object) -> bool:
|
|
if not self and isinstance(other, list):
|
|
return True
|
|
if not isinstance(other, list) or len(self) != len(other):
|
|
return False
|
|
for i, v in enumerate(self):
|
|
if v == other[i]:
|
|
continue
|
|
else:
|
|
return False
|
|
else:
|
|
return True
|
|
|
|
|
|
class AnyInt(int):
|
|
def __init__(self) -> None:
|
|
super().__init__()
|
|
|
|
def __eq__(self, other: object) -> bool:
|
|
return isinstance(other, int)
|