Skip to content

Commit d2062bb

Browse files
fix(package): support direct resource imports
1 parent 5dce648 commit d2062bb

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/finch/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3+
import typing as _t
4+
35
from . import types
46
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes
57
from ._utils import file_from_path
@@ -68,6 +70,9 @@
6870
"DefaultAsyncHttpxClient",
6971
]
7072

73+
if not _t.TYPE_CHECKING:
74+
from ._utils._resources_proxy import resources as resources
75+
7176
_setup_logging()
7277

7378
# Update the __module__ attribute for exported symbols so that

src/finch/_utils/_resources_proxy.py

Lines changed: 24 additions & 0 deletions
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 `finch.resources` module.
11+
12+
This is used so that we can lazily import `finch.resources` only when
13+
needed *and* so that users can just import `finch` and reference `finch.resources`
14+
"""
15+
16+
@override
17+
def __load__(self) -> Any:
18+
import importlib
19+
20+
mod = importlib.import_module("finch.resources")
21+
return mod
22+
23+
24+
resources = ResourcesProxy().__as_proxied__()

0 commit comments

Comments
 (0)