|
14 | 14 |
|
15 | 15 | from __future__ import absolute_import |
16 | 16 |
|
17 | | -from .create_from_yaml import ( |
18 | | - FailToCreateError, create_from_dict, create_from_yaml, |
19 | | - create_from_yaml_single_item, |
20 | | -) |
| 17 | +import typing as _typing |
| 18 | + |
21 | 19 | from .retry import (Backoff, DEFAULT_BACKOFF, DEFAULT_RETRY, |
22 | 20 | DEFAULT_RETRY_AFTER_BACKOFF, on_error, |
23 | 21 | on_retry_after_error, retry_on_conflict, |
24 | 22 | is_conflict, is_retry_after_response, |
25 | 23 | is_too_many_requests, retry_after_backoff, |
26 | 24 | retry_after_max_retries, retry_after_seconds) |
| 25 | + |
| 26 | + |
| 27 | +__all__ = [ |
| 28 | + "FailToCreateError", |
| 29 | + "create_from_dict", |
| 30 | + "create_from_yaml", |
| 31 | + "create_from_yaml_single_item", |
| 32 | + "Backoff", |
| 33 | + "DEFAULT_BACKOFF", |
| 34 | + "DEFAULT_RETRY", |
| 35 | + "DEFAULT_RETRY_AFTER_BACKOFF", |
| 36 | + "on_error", |
| 37 | + "on_retry_after_error", |
| 38 | + "retry_on_conflict", |
| 39 | + "is_conflict", |
| 40 | + "is_retry_after_response", |
| 41 | + "is_too_many_requests", |
| 42 | + "retry_after_backoff", |
| 43 | + "retry_after_max_retries", |
| 44 | + "retry_after_seconds", |
| 45 | +] |
| 46 | + |
| 47 | + |
| 48 | +# REST imports retry while client is initializing, so defer client-dependent utilities. |
| 49 | +if _typing.TYPE_CHECKING: |
| 50 | + from .create_from_yaml import ( |
| 51 | + FailToCreateError, create_from_dict, create_from_yaml, |
| 52 | + create_from_yaml_single_item, |
| 53 | + ) |
| 54 | +else: |
| 55 | + from importlib import import_module |
| 56 | + |
| 57 | + _exports = { |
| 58 | + "FailToCreateError": ".create_from_yaml", |
| 59 | + "create_from_dict": ".create_from_yaml", |
| 60 | + "create_from_yaml": ".create_from_yaml", |
| 61 | + "create_from_yaml_single_item": ".create_from_yaml", |
| 62 | + } |
| 63 | + |
| 64 | + def __getattr__(name: str) -> object: |
| 65 | + if (module_name := _exports.get(name)) is None: |
| 66 | + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") |
| 67 | + module = import_module(module_name, __name__) |
| 68 | + for export, export_module in _exports.items(): |
| 69 | + if export_module == module_name: |
| 70 | + globals()[export] = getattr(module, export) |
| 71 | + return globals()[name] |
| 72 | + |
| 73 | + def __dir__() -> list[str]: |
| 74 | + return sorted(globals().keys() | _exports.keys()) |
0 commit comments