From 461c96049bc4c1331d112bedad581c3702a2dbe1 Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Wed, 17 Apr 2024 22:43:14 +0000 Subject: [PATCH] chore: update SDK settings --- pyproject.toml | 7 ++++++- src/riza/_base_client.py | 3 +-- src/riza/_models.py | 2 +- src/riza/_utils/__init__.py | 1 + src/riza/_utils/_utils.py | 10 ++++++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2ffeaee..9556e12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -161,7 +161,9 @@ select = [ "T201", "T203", # misuse of typing.TYPE_CHECKING - "TCH004" + "TCH004", + # import rules + "TID251", ] ignore = [ # mutable defaults @@ -177,6 +179,9 @@ ignore-init-module-imports = true [tool.ruff.format] docstring-code-format = true +[tool.ruff.lint.flake8-tidy-imports.banned-api] +"functools.lru_cache".msg = "This function does not retain type information for the wrapped function's arguments; The `lru_cache` function from `_utils` should be used instead" + [tool.ruff.lint.isort] length-sort = true length-sort-straight = true diff --git a/src/riza/_base_client.py b/src/riza/_base_client.py index baae8f3..9569c70 100644 --- a/src/riza/_base_client.py +++ b/src/riza/_base_client.py @@ -29,7 +29,6 @@ cast, overload, ) -from functools import lru_cache from typing_extensions import Literal, override, get_origin import anyio @@ -61,7 +60,7 @@ RequestOptions, ModelBuilderProtocol, ) -from ._utils import is_dict, is_list, is_given, is_mapping +from ._utils import is_dict, is_list, is_given, lru_cache, is_mapping from ._compat import model_copy, model_dump from ._models import GenericModel, FinalRequestOptions, validate_type, construct_type from ._response import ( diff --git a/src/riza/_models.py b/src/riza/_models.py index 80ab512..ff93fbd 100644 --- a/src/riza/_models.py +++ b/src/riza/_models.py @@ -4,7 +4,6 @@ import inspect from typing import TYPE_CHECKING, Any, Type, Union, Generic, TypeVar, Callable, cast from datetime import date, datetime -from functools import lru_cache from typing_extensions import ( Unpack, Literal, @@ -37,6 +36,7 @@ PropertyInfo, is_list, is_given, + lru_cache, is_mapping, parse_date, coerce_boolean, diff --git a/src/riza/_utils/__init__.py b/src/riza/_utils/__init__.py index 5697894..31b5b22 100644 --- a/src/riza/_utils/__init__.py +++ b/src/riza/_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/riza/_utils/_utils.py b/src/riza/_utils/_utils.py index 93c9551..fd3a8a4 100644 --- a/src/riza/_utils/_utils.py +++ b/src/riza/_utils/_utils.py @@ -389,3 +389,13 @@ 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( # noqa: TID251 + maxsize=maxsize, + ) + return cast(Any, wrapper) # type: ignore[no-any-return]