Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0005b7c

Browse files
fix(package): support direct resource imports
1 parent 85e6888 commit 0005b7c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/openai/__init__.py

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

33
from __future__ import annotations
44

5+
import typing as _t
56
from typing_extensions import override
67

78
from . import types
@@ -72,6 +73,9 @@
7273
"DefaultAsyncHttpxClient",
7374
]
7475

76+
if not _t.TYPE_CHECKING:
77+
from ._utils._resources_proxy import resources as resources
78+
7579
_setup_logging()
7680

7781
# Update the __module__ attribute for exported symbols so that

src/openai/_utils/_resources_proxy.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
from typing_extensions import override
5+
6+
from ._proxy import LazyProxy
7+
8+
9+
class ResourcesProxy(LazyProxy[Any]):
10+
"""A proxy for the `openai.resources` module.
11+
12+
This is used so that we can lazily import `openai.resources` only when
13+
needed *and* so that users can just import `openai` and reference `openai.resources`
14+
"""
15+
16+
@override
17+
def __load__(self) -> Any:
18+
import importlib
19+
20+
mod = importlib.import_module("openai.resources")
21+
return mod
22+
23+
24+
resources = ResourcesProxy().__as_proxied__()

0 commit comments

Comments
 (0)