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

Lines 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

Lines changed: 11 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy