diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 6b7b74c5..cce92405 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.3.0" + ".": "0.3.1" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index bbf66791..c132c84c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## 0.3.1 (2025-05-10) + +Full Changelog: [v0.3.0...v0.3.1](https://github.com/mixedbread-ai/mixedbread-python/compare/v0.3.0...v0.3.1) + +### Bug Fixes + +* **package:** support direct resource imports ([95be7c3](https://github.com/mixedbread-ai/mixedbread-python/commit/95be7c333ec101050db0539b2d955baa8347171b)) + + +### Chores + +* **internal:** avoid errors for isinstance checks on proxies ([08890c1](https://github.com/mixedbread-ai/mixedbread-python/commit/08890c17a698ba50acfc1343439d8311d6aaf2f5)) +* **internal:** avoid lint errors in pagination expressions ([0b0c882](https://github.com/mixedbread-ai/mixedbread-python/commit/0b0c8827c390e46ef302e10f0a1d504237ce6501)) + ## 0.3.0 (2025-05-03) Full Changelog: [v0.2.1...v0.3.0](https://github.com/mixedbread-ai/mixedbread-python/compare/v0.2.1...v0.3.0) diff --git a/pyproject.toml b/pyproject.toml index 1d52ff5f..91395731 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "mixedbread" -version = "0.3.0" +version = "0.3.1" description = "The official Python library for the Mixedbread API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/mixedbread/__init__.py b/src/mixedbread/__init__.py index c6b40046..022e49ef 100644 --- a/src/mixedbread/__init__.py +++ b/src/mixedbread/__init__.py @@ -1,5 +1,7 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +import typing as _t + from . import types from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes from ._utils import file_from_path @@ -80,6 +82,9 @@ "DefaultAsyncHttpxClient", ] +if not _t.TYPE_CHECKING: + from ._utils._resources_proxy import resources as resources + _setup_logging() # Update the __module__ attribute for exported symbols so that diff --git a/src/mixedbread/_utils/_proxy.py b/src/mixedbread/_utils/_proxy.py index ffd883e9..0f239a33 100644 --- a/src/mixedbread/_utils/_proxy.py +++ b/src/mixedbread/_utils/_proxy.py @@ -46,7 +46,10 @@ def __dir__(self) -> Iterable[str]: @property # type: ignore @override def __class__(self) -> type: # pyright: ignore - proxied = self.__get_proxied__() + try: + proxied = self.__get_proxied__() + except Exception: + return type(self) if issubclass(type(proxied), LazyProxy): return type(proxied) return proxied.__class__ diff --git a/src/mixedbread/_utils/_resources_proxy.py b/src/mixedbread/_utils/_resources_proxy.py new file mode 100644 index 00000000..ad97bb05 --- /dev/null +++ b/src/mixedbread/_utils/_resources_proxy.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from typing import Any +from typing_extensions import override + +from ._proxy import LazyProxy + + +class ResourcesProxy(LazyProxy[Any]): + """A proxy for the `mixedbread.resources` module. + + This is used so that we can lazily import `mixedbread.resources` only when + needed *and* so that users can just import `mixedbread` and reference `mixedbread.resources` + """ + + @override + def __load__(self) -> Any: + import importlib + + mod = importlib.import_module("mixedbread.resources") + return mod + + +resources = ResourcesProxy().__as_proxied__() diff --git a/src/mixedbread/_version.py b/src/mixedbread/_version.py index 0007f447..7e6e8c04 100644 --- a/src/mixedbread/_version.py +++ b/src/mixedbread/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "mixedbread" -__version__ = "0.3.0" # x-release-please-version +__version__ = "0.3.1" # x-release-please-version diff --git a/src/mixedbread/pagination.py b/src/mixedbread/pagination.py index b7df01d1..c2f1ea59 100644 --- a/src/mixedbread/pagination.py +++ b/src/mixedbread/pagination.py @@ -35,7 +35,7 @@ def next_page_info(self) -> Optional[PageInfo]: if self.pagination.offset is not None: offset = self.pagination.offset if offset is None: - return None + return None # type: ignore[unreachable] length = len(self._get_page_items()) current_count = offset + length @@ -71,7 +71,7 @@ def next_page_info(self) -> Optional[PageInfo]: if self.pagination.offset is not None: offset = self.pagination.offset if offset is None: - return None + return None # type: ignore[unreachable] length = len(self._get_page_items()) current_count = offset + length diff --git a/tests/test_utils/test_proxy.py b/tests/test_utils/test_proxy.py index 9b54af18..76104cef 100644 --- a/tests/test_utils/test_proxy.py +++ b/tests/test_utils/test_proxy.py @@ -21,3 +21,14 @@ def test_recursive_proxy() -> None: assert dir(proxy) == [] assert type(proxy).__name__ == "RecursiveLazyProxy" assert type(operator.attrgetter("name.foo.bar.baz")(proxy)).__name__ == "RecursiveLazyProxy" + + +def test_isinstance_does_not_error() -> None: + class AlwaysErrorProxy(LazyProxy[Any]): + @override + def __load__(self) -> Any: + raise RuntimeError("Mocking missing dependency") + + proxy = AlwaysErrorProxy() + assert not isinstance(proxy, dict) + assert isinstance(proxy, LazyProxy)