|
2 | 2 |
|
3 | 3 | # isort: skip_file |
4 | 4 |
|
5 | | -from .api_error import ApiError |
6 | | -from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper |
7 | | -from .datetime_utils import serialize_datetime |
8 | | -from .events import EventEmitterMixin, EventType |
9 | | -from .file import File, convert_file_dict_to_httpx_tuples, with_content_type |
10 | | -from .http_client import AsyncHttpClient, HttpClient |
11 | | -from .http_response import AsyncHttpResponse, HttpResponse |
12 | | -from .jsonable_encoder import jsonable_encoder |
13 | | -from .pydantic_utilities import ( |
14 | | - IS_PYDANTIC_V2, |
15 | | - UniversalBaseModel, |
16 | | - UniversalRootModel, |
17 | | - parse_obj_as, |
18 | | - universal_field_validator, |
19 | | - universal_root_validator, |
20 | | - update_forward_refs, |
21 | | -) |
22 | | -from .query_encoder import encode_query |
23 | | -from .remove_none_from_dict import remove_none_from_dict |
24 | | -from .request_options import RequestOptions |
25 | | -from .serialization import FieldMetadata, convert_and_respect_annotation_metadata |
| 5 | +import typing |
| 6 | +from importlib import import_module |
| 7 | + |
| 8 | +if typing.TYPE_CHECKING: |
| 9 | + from .api_error import ApiError |
| 10 | + from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper |
| 11 | + from .datetime_utils import serialize_datetime |
| 12 | + from .events import EventEmitterMixin, EventType |
| 13 | + from .file import File, convert_file_dict_to_httpx_tuples, with_content_type |
| 14 | + from .http_client import AsyncHttpClient, HttpClient |
| 15 | + from .http_response import AsyncHttpResponse, HttpResponse |
| 16 | + from .jsonable_encoder import jsonable_encoder |
| 17 | + from .pydantic_utilities import ( |
| 18 | + IS_PYDANTIC_V2, |
| 19 | + UniversalBaseModel, |
| 20 | + UniversalRootModel, |
| 21 | + parse_obj_as, |
| 22 | + universal_field_validator, |
| 23 | + universal_root_validator, |
| 24 | + update_forward_refs, |
| 25 | + ) |
| 26 | + from .query_encoder import encode_query |
| 27 | + from .remove_none_from_dict import remove_none_from_dict |
| 28 | + from .request_options import RequestOptions |
| 29 | + from .serialization import FieldMetadata, convert_and_respect_annotation_metadata |
| 30 | +_dynamic_imports: typing.Dict[str, str] = { |
| 31 | + "ApiError": ".api_error", |
| 32 | + "AsyncClientWrapper": ".client_wrapper", |
| 33 | + "AsyncHttpClient": ".http_client", |
| 34 | + "AsyncHttpResponse": ".http_response", |
| 35 | + "BaseClientWrapper": ".client_wrapper", |
| 36 | + "EventEmitterMixin": ".events", |
| 37 | + "EventType": ".events", |
| 38 | + "FieldMetadata": ".serialization", |
| 39 | + "File": ".file", |
| 40 | + "HttpClient": ".http_client", |
| 41 | + "HttpResponse": ".http_response", |
| 42 | + "IS_PYDANTIC_V2": ".pydantic_utilities", |
| 43 | + "RequestOptions": ".request_options", |
| 44 | + "SyncClientWrapper": ".client_wrapper", |
| 45 | + "UniversalBaseModel": ".pydantic_utilities", |
| 46 | + "UniversalRootModel": ".pydantic_utilities", |
| 47 | + "convert_and_respect_annotation_metadata": ".serialization", |
| 48 | + "convert_file_dict_to_httpx_tuples": ".file", |
| 49 | + "encode_query": ".query_encoder", |
| 50 | + "jsonable_encoder": ".jsonable_encoder", |
| 51 | + "parse_obj_as": ".pydantic_utilities", |
| 52 | + "remove_none_from_dict": ".remove_none_from_dict", |
| 53 | + "serialize_datetime": ".datetime_utils", |
| 54 | + "universal_field_validator": ".pydantic_utilities", |
| 55 | + "universal_root_validator": ".pydantic_utilities", |
| 56 | + "update_forward_refs": ".pydantic_utilities", |
| 57 | + "with_content_type": ".file", |
| 58 | +} |
| 59 | + |
| 60 | + |
| 61 | +def __getattr__(attr_name: str) -> typing.Any: |
| 62 | + module_name = _dynamic_imports.get(attr_name) |
| 63 | + if module_name is None: |
| 64 | + raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}") |
| 65 | + try: |
| 66 | + module = import_module(module_name, __package__) |
| 67 | + if module_name == f".{attr_name}": |
| 68 | + return module |
| 69 | + else: |
| 70 | + return getattr(module, attr_name) |
| 71 | + except ImportError as e: |
| 72 | + raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e |
| 73 | + except AttributeError as e: |
| 74 | + raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e |
| 75 | + |
| 76 | + |
| 77 | +def __dir__(): |
| 78 | + lazy_attrs = list(_dynamic_imports.keys()) |
| 79 | + return sorted(lazy_attrs) |
| 80 | + |
26 | 81 |
|
27 | 82 | __all__ = [ |
28 | 83 | "ApiError", |
|
0 commit comments