Skip to content

Commit 3de384b

Browse files
chore(internal): avoid errors for isinstance checks on proxies
1 parent f990977 commit 3de384b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/openlayer/_utils/_proxy.py

+4-1
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

+11
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,14 @@ def test_recursive_proxy() -> None:
2121
assert dir(proxy) == []
2222
assert type(proxy).__name__ == "RecursiveLazyProxy"
2323
assert type(operator.attrgetter("name.foo.bar.baz")(proxy)).__name__ == "RecursiveLazyProxy"
24+
25+
26+
def test_isinstance_does_not_error() -> None:
27+
class AlwaysErrorProxy(LazyProxy[Any]):
28+
@override
29+
def __load__(self) -> Any:
30+
raise RuntimeError("Mocking missing dependency")
31+
32+
proxy = AlwaysErrorProxy()
33+
assert not isinstance(proxy, dict)
34+
assert isinstance(proxy, LazyProxy)

0 commit comments

Comments
 (0)