Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 0.7.7 #259

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.7.6"
".": "0.7.7"
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.7.7 (2023-11-29)

Full Changelog: [v0.7.6...v0.7.7](https://github.com/anthropics/anthropic-sdk-python/compare/v0.7.6...v0.7.7)

### Chores

* **internal:** add tests for proxy change ([#260](https://github.com/anthropics/anthropic-sdk-python/issues/260)) ([3b52136](https://github.com/anthropics/anthropic-sdk-python/commit/3b521362f6ee33c3ff66371e4f2d3bdcea2827bb))
* **internal:** updates to proxy helper ([#258](https://github.com/anthropics/anthropic-sdk-python/issues/258)) ([94c4de8](https://github.com/anthropics/anthropic-sdk-python/commit/94c4de88b9d202d780c4dfbee6db138d7a663373))

## 0.7.6 (2023-11-28)

Full Changelog: [v0.7.5...v0.7.6](https://github.com/anthropics/anthropic-sdk-python/compare/v0.7.5...v0.7.6)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "anthropic"
version = "0.7.6"
version = "0.7.7"
description = "The official Python library for the anthropic API"
readme = "README.md"
license = "MIT"
Expand Down
26 changes: 22 additions & 4 deletions src/anthropic/_utils/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,43 @@ class LazyProxy(Generic[T], ABC):
def __init__(self) -> None:
self.__proxied: T | None = None

# Note: we have to special case proxies that themselves return proxies
# to support using a proxy as a catch-all for any random access, e.g. `proxy.foo.bar.baz`

def __getattr__(self, attr: str) -> object:
return getattr(self.__get_proxied__(), attr)
proxied = self.__get_proxied__()
if isinstance(proxied, LazyProxy):
return proxied # pyright: ignore
return getattr(proxied, attr)

@override
def __repr__(self) -> str:
proxied = self.__get_proxied__()
if isinstance(proxied, LazyProxy):
return proxied.__class__.__name__
return repr(self.__get_proxied__())

@override
def __str__(self) -> str:
return str(self.__get_proxied__())
proxied = self.__get_proxied__()
if isinstance(proxied, LazyProxy):
return proxied.__class__.__name__
return str(proxied)

@override
def __dir__(self) -> Iterable[str]:
return self.__get_proxied__().__dir__()
proxied = self.__get_proxied__()
if isinstance(proxied, LazyProxy):
return []
return proxied.__dir__()

@property # type: ignore
@override
def __class__(self) -> type:
return self.__get_proxied__().__class__
proxied = self.__get_proxied__()
if issubclass(type(proxied), LazyProxy):
return type(proxied)
return proxied.__class__

def __get_proxied__(self) -> T:
if not self.should_cache:
Expand Down
2 changes: 1 addition & 1 deletion src/anthropic/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless.

__title__ = "anthropic"
__version__ = "0.7.6" # x-release-please-version
__version__ = "0.7.7" # x-release-please-version
23 changes: 23 additions & 0 deletions tests/test_utils/test_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import operator
from typing import Any
from typing_extensions import override

from anthropic._utils import LazyProxy


class RecursiveLazyProxy(LazyProxy[Any]):
@override
def __load__(self) -> Any:
return self

def __call__(self, *_args: Any, **_kwds: Any) -> Any:
raise RuntimeError("This should never be called!")


def test_recursive_proxy() -> None:
proxy = RecursiveLazyProxy()
assert repr(proxy) == "RecursiveLazyProxy"
assert str(proxy) == "RecursiveLazyProxy"
assert dir(proxy) == []
assert getattr(type(proxy), "__name__") == "RecursiveLazyProxy"
assert type(operator.attrgetter("name.foo.bar.baz")(proxy)).__name__ == "RecursiveLazyProxy"