Skip to content

Commit

Permalink
chore(internal): add lru_cache helper function (#1329)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Apr 17, 2024
1 parent bb95fe3 commit b8f7ee5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/openai/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/openai/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit b8f7ee5

Please sign in to comment.