From a05b1607440d1b5917a015e6e761acbb15f47cf4 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Tue, 16 Jan 2024 11:47:21 -0500 Subject: [PATCH] fix(proxy): prevent recursion errors when debugging pycharm (#1076) https://github.com/openai/openai-python/issues/906 --- src/openai/_extras/numpy_proxy.py | 4 +--- src/openai/_extras/pandas_proxy.py | 4 +--- src/openai/_utils/_proxy.py | 20 ++------------------ 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/openai/_extras/numpy_proxy.py b/src/openai/_extras/numpy_proxy.py index 3809991c46..27880bf132 100644 --- a/src/openai/_extras/numpy_proxy.py +++ b/src/openai/_extras/numpy_proxy.py @@ -1,7 +1,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Any -from typing_extensions import ClassVar, override +from typing_extensions import override from .._utils import LazyProxy from ._common import MissingDependencyError, format_instructions @@ -14,8 +14,6 @@ class NumpyProxy(LazyProxy[Any]): - should_cache: ClassVar[bool] = True - @override def __load__(self) -> Any: try: diff --git a/src/openai/_extras/pandas_proxy.py b/src/openai/_extras/pandas_proxy.py index a24f7fb604..686377bade 100644 --- a/src/openai/_extras/pandas_proxy.py +++ b/src/openai/_extras/pandas_proxy.py @@ -1,7 +1,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Any -from typing_extensions import ClassVar, override +from typing_extensions import override from .._utils import LazyProxy from ._common import MissingDependencyError, format_instructions @@ -14,8 +14,6 @@ class PandasProxy(LazyProxy[Any]): - should_cache: ClassVar[bool] = True - @override def __load__(self) -> Any: try: diff --git a/src/openai/_utils/_proxy.py b/src/openai/_utils/_proxy.py index 3c9e790a25..6f05efcd21 100644 --- a/src/openai/_utils/_proxy.py +++ b/src/openai/_utils/_proxy.py @@ -2,7 +2,7 @@ from abc import ABC, abstractmethod from typing import Generic, TypeVar, Iterable, cast -from typing_extensions import ClassVar, override +from typing_extensions import override T = TypeVar("T") @@ -13,11 +13,6 @@ class LazyProxy(Generic[T], ABC): This includes forwarding attribute access and othe methods. """ - should_cache: ClassVar[bool] = False - - 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` @@ -57,18 +52,7 @@ def __class__(self) -> type: return proxied.__class__ def __get_proxied__(self) -> T: - if not self.should_cache: - return self.__load__() - - proxied = self.__proxied - if proxied is not None: - return proxied - - self.__proxied = proxied = self.__load__() - return proxied - - def __set_proxied__(self, value: T) -> None: - self.__proxied = value + return self.__load__() def __as_proxied__(self) -> T: """Helper method that returns the current proxy, typed as the loaded object"""