Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(proxy): prevent recursion errors when debugging pycharm #1076

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/openai/_extras/numpy_proxy.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,8 +14,6 @@


class NumpyProxy(LazyProxy[Any]):
should_cache: ClassVar[bool] = True

@override
def __load__(self) -> Any:
try:
Expand Down
4 changes: 1 addition & 3 deletions src/openai/_extras/pandas_proxy.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,8 +14,6 @@


class PandasProxy(LazyProxy[Any]):
should_cache: ClassVar[bool] = True

@override
def __load__(self) -> Any:
try:
Expand Down
20 changes: 2 additions & 18 deletions src/openai/_utils/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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`

Expand Down Expand Up @@ -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"""
Expand Down