diff --git a/src/anthropic/_utils/__init__.py b/src/anthropic/_utils/__init__.py index 56978941..31b5b227 100644 --- a/src/anthropic/_utils/__init__.py +++ b/src/anthropic/_utils/__init__.py @@ -6,6 +6,7 @@ is_list as is_list, is_given as is_given, is_tuple as is_tuple, + lru_cache as lru_cache, is_mapping as is_mapping, is_tuple_t as is_tuple_t, parse_date as parse_date, diff --git a/src/anthropic/_utils/_utils.py b/src/anthropic/_utils/_utils.py index 93c95517..5123a230 100644 --- a/src/anthropic/_utils/_utils.py +++ b/src/anthropic/_utils/_utils.py @@ -389,3 +389,11 @@ def get_async_library() -> str: return sniffio.current_async_library() except Exception: return "false" + + +def lru_cache(*, maxsize: int | None = 128) -> Callable[[CallableT], CallableT]: + """A version of functools.lru_cache that retains the type signature + for the wrapped function arguments. + """ + wrapper = functools.lru_cache(maxsize=maxsize) + return cast(Any, wrapper) # type: ignore[no-any-return] diff --git a/src/anthropic/lib/bedrock/_auth.py b/src/anthropic/lib/bedrock/_auth.py index caae0100..95c820f6 100644 --- a/src/anthropic/lib/bedrock/_auth.py +++ b/src/anthropic/lib/bedrock/_auth.py @@ -1,10 +1,11 @@ from __future__ import annotations from typing import TYPE_CHECKING -from functools import lru_cache import httpx +from ..._utils import lru_cache + if TYPE_CHECKING: import boto3 @@ -42,9 +43,9 @@ def get_auth_headers( from botocore.awsrequest import AWSRequest session = _get_session( - region_name=region, - aws_access_key_id=aws_access_key, - aws_secret_access_key=aws_secret_key, + region=region, + aws_access_key=aws_access_key, + aws_secret_key=aws_secret_key, aws_session_token=aws_session_token, )