diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 0c2ecec6..461342f9 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.20.0" + ".": "0.20.1" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a730757e..dd6f107d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 0.20.1 (2024-04-18) + +Full Changelog: [v0.20.0...v0.20.1](https://github.com/Finch-API/finch-api-python/compare/v0.20.0...v0.20.1) + +### Chores + +* **internal:** add lru_cache helper function ([#352](https://github.com/Finch-API/finch-api-python/issues/352)) ([2856451](https://github.com/Finch-API/finch-api-python/commit/2856451e956fa7bd70ddc9ff58cd1c7dba01f616)) +* **internal:** ban usage of lru_cache ([#354](https://github.com/Finch-API/finch-api-python/issues/354)) ([d909f7d](https://github.com/Finch-API/finch-api-python/commit/d909f7dd0dba483a4ce1fd4dbd842a5649091f99)) +* **internal:** bump pyright to 1.1.359 ([#355](https://github.com/Finch-API/finch-api-python/issues/355)) ([a489290](https://github.com/Finch-API/finch-api-python/commit/a489290f45562abf37ec58e01c911ab8c76dcf11)) + ## 0.20.0 (2024-04-12) Full Changelog: [v0.19.1...v0.20.0](https://github.com/Finch-API/finch-api-python/compare/v0.19.1...v0.20.0) diff --git a/pyproject.toml b/pyproject.toml index 4881554a..535e0c18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "finch-api" -version = "0.20.0" +version = "0.20.1" description = "The official Python library for the Finch API" dynamic = ["readme"] license = "Apache-2.0" @@ -48,7 +48,7 @@ Repository = "https://github.com/Finch-API/finch-api-python" managed = true # version pins are in requirements-dev.lock dev-dependencies = [ - "pyright", + "pyright>=1.1.359", "mypy", "respx", "pytest", @@ -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/requirements-dev.lock b/requirements-dev.lock index 672caedf..0407fa1e 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -63,7 +63,7 @@ pydantic==2.4.2 # via finch-api pydantic-core==2.10.1 # via pydantic -pyright==1.1.353 +pyright==1.1.359 pytest==7.1.1 # via pytest-asyncio pytest-asyncio==0.21.1 diff --git a/src/finch/_base_client.py b/src/finch/_base_client.py index b936cf2b..fc1fedb7 100644 --- a/src/finch/_base_client.py +++ b/src/finch/_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/finch/_models.py b/src/finch/_models.py index 80ab5125..ff3f54e2 100644 --- a/src/finch/_models.py +++ b/src/finch/_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, @@ -378,7 +378,7 @@ def construct_type(*, value: object, type_: object) -> object: # unwrap `Annotated[T, ...]` -> `T` if is_annotated_type(type_): - meta = get_args(type_)[1:] + meta: tuple[Any, ...] = get_args(type_)[1:] type_ = extract_type_arg(type_, 0) else: meta = tuple() diff --git a/src/finch/_utils/__init__.py b/src/finch/_utils/__init__.py index 56978941..31b5b227 100644 --- a/src/finch/_utils/__init__.py +++ b/src/finch/_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/finch/_utils/_utils.py b/src/finch/_utils/_utils.py index 93c95517..17904ce6 100644 --- a/src/finch/_utils/_utils.py +++ b/src/finch/_utils/_utils.py @@ -265,6 +265,8 @@ def wrapper(*args: object, **kwargs: object) -> object: ) msg = f"Missing required arguments; Expected either {variations} arguments to be given" else: + assert len(variants) > 0 + # TODO: this error message is not deterministic missing = list(set(variants[0]) - given_params) if len(missing) > 1: @@ -389,3 +391,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] diff --git a/src/finch/_version.py b/src/finch/_version.py index 62b120d1..6f6f25b8 100644 --- a/src/finch/_version.py +++ b/src/finch/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "finch" -__version__ = "0.20.0" # x-release-please-version +__version__ = "0.20.1" # x-release-please-version