Skip to content

Commit 3d78798

Browse files
fix(proxy): prevent recursion errors when debugging pycharm (#1076)
#906
1 parent 9a25149 commit 3d78798

File tree

3 files changed

+4
-24
lines changed

3 files changed

+4
-24
lines changed

src/openai/_extras/numpy_proxy.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from typing import TYPE_CHECKING, Any
4-
from typing_extensions import ClassVar, override
4+
from typing_extensions import override
55

66
from .._utils import LazyProxy
77
from ._common import MissingDependencyError, format_instructions
@@ -14,8 +14,6 @@
1414

1515

1616
class NumpyProxy(LazyProxy[Any]):
17-
should_cache: ClassVar[bool] = True
18-
1917
@override
2018
def __load__(self) -> Any:
2119
try:

src/openai/_extras/pandas_proxy.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from typing import TYPE_CHECKING, Any
4-
from typing_extensions import ClassVar, override
4+
from typing_extensions import override
55

66
from .._utils import LazyProxy
77
from ._common import MissingDependencyError, format_instructions
@@ -14,8 +14,6 @@
1414

1515

1616
class PandasProxy(LazyProxy[Any]):
17-
should_cache: ClassVar[bool] = True
18-
1917
@override
2018
def __load__(self) -> Any:
2119
try:

src/openai/_utils/_proxy.py

+2-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from abc import ABC, abstractmethod
44
from typing import Generic, TypeVar, Iterable, cast
5-
from typing_extensions import ClassVar, override
5+
from typing_extensions import override
66

77
T = TypeVar("T")
88

@@ -13,11 +13,6 @@ class LazyProxy(Generic[T], ABC):
1313
This includes forwarding attribute access and othe methods.
1414
"""
1515

16-
should_cache: ClassVar[bool] = False
17-
18-
def __init__(self) -> None:
19-
self.__proxied: T | None = None
20-
2116
# Note: we have to special case proxies that themselves return proxies
2217
# to support using a proxy as a catch-all for any random access, e.g. `proxy.foo.bar.baz`
2318

@@ -57,18 +52,7 @@ def __class__(self) -> type:
5752
return proxied.__class__
5853

5954
def __get_proxied__(self) -> T:
60-
if not self.should_cache:
61-
return self.__load__()
62-
63-
proxied = self.__proxied
64-
if proxied is not None:
65-
return proxied
66-
67-
self.__proxied = proxied = self.__load__()
68-
return proxied
69-
70-
def __set_proxied__(self, value: T) -> None:
71-
self.__proxied = value
55+
return self.__load__()
7256

7357
def __as_proxied__(self) -> T:
7458
"""Helper method that returns the current proxy, typed as the loaded object"""

0 commit comments

Comments
 (0)