Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 08d67ad

Browse filesBrowse files
browniebrokestainless-app[bot]
authored andcommitted
fix: ignore errors in isinstance() calls on LazyProxy subclasses (#2343)
Fix #2056
1 parent 917dade commit 08d67ad
Copy full SHA for 08d67ad

File tree

Expand file treeCollapse file tree

2 files changed

+16
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-1
lines changed

‎src/openai/_utils/_proxy.py

Copy file name to clipboardExpand all lines: src/openai/_utils/_proxy.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ def __dir__(self) -> Iterable[str]:
4646
@property # type: ignore
4747
@override
4848
def __class__(self) -> type: # pyright: ignore
49-
proxied = self.__get_proxied__()
49+
try:
50+
proxied = self.__get_proxied__()
51+
except Exception:
52+
return type(self)
5053
if issubclass(type(proxied), LazyProxy):
5154
return type(proxied)
5255
return proxied.__class__

‎tests/test_utils/test_proxy.py

Copy file name to clipboardExpand all lines: tests/test_utils/test_proxy.py
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing_extensions import override
44

55
from openai._utils import LazyProxy
6+
from openai._extras._common import MissingDependencyError
67

78

89
class RecursiveLazyProxy(LazyProxy[Any]):
@@ -21,3 +22,14 @@ def test_recursive_proxy() -> None:
2122
assert dir(proxy) == []
2223
assert type(proxy).__name__ == "RecursiveLazyProxy"
2324
assert type(operator.attrgetter("name.foo.bar.baz")(proxy)).__name__ == "RecursiveLazyProxy"
25+
26+
27+
def test_is_instance_with_missing_dependency_error() -> None:
28+
class MissingDepsProxy(LazyProxy[Any]):
29+
@override
30+
def __load__(self) -> Any:
31+
raise MissingDependencyError("Mocking missing dependency")
32+
33+
proxy = MissingDepsProxy()
34+
assert not isinstance(proxy, dict)
35+
assert isinstance(proxy, LazyProxy)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.