|
14 | 14 |
|
15 | 15 | """Package for interacting with the google.longrunning.operations meta-API.""" |
16 | 16 |
|
17 | | -from google.api_core.operations_v1.abstract_operations_client import AbstractOperationsClient |
18 | | -from google.api_core.operations_v1.operations_async_client import OperationsAsyncClient |
19 | | -from google.api_core.operations_v1.operations_client import OperationsClient |
20 | | -from google.api_core.operations_v1.transports.rest import OperationsRestTransport |
| 17 | +import importlib.util |
| 18 | +from typing import Set |
| 19 | + |
| 20 | +_has_async_rest = ( |
| 21 | + importlib.util.find_spec("google.auth.aio.transport.sessions") is not None |
| 22 | +) |
| 23 | + |
| 24 | +# PEP 0810: Explicit Lazy Imports |
| 25 | +# Python 3.15+ natively intercepts and defers these imports. |
| 26 | +# Developers can disable this behavior and force eager imports. |
| 27 | +# For more information, see: |
| 28 | +# https://docs.python.org/3.15/library/sys.html#sys.set_lazy_imports_filter |
| 29 | +# Older Python versions safely ignore this variable. |
| 30 | +__lazy_modules__: Set[str] = { |
| 31 | + "google.api_core.operations_v1.abstract_operations_client", |
| 32 | + "google.api_core.operations_v1.operations_async_client", |
| 33 | + "google.api_core.operations_v1.operations_client", |
| 34 | + "google.api_core.operations_v1.transports.rest", |
| 35 | +} |
21 | 36 |
|
22 | 37 | __all__ = [ |
23 | 38 | "AbstractOperationsClient", |
24 | 39 | "OperationsAsyncClient", |
25 | 40 | "OperationsClient", |
26 | | - "OperationsRestTransport" |
| 41 | + "OperationsRestTransport", |
27 | 42 | ] |
28 | 43 |
|
29 | | -try: |
30 | | - from google.api_core.operations_v1.transports.rest_asyncio import ( |
31 | | - AsyncOperationsRestTransport, |
| 44 | +if _has_async_rest: |
| 45 | + __lazy_modules__.update( |
| 46 | + { |
| 47 | + "google.api_core.operations_v1.transports.rest_asyncio", |
| 48 | + "google.api_core.operations_v1.operations_rest_client_async", |
| 49 | + } |
32 | 50 | ) |
33 | | - from google.api_core.operations_v1.operations_rest_client_async import AsyncOperationsRestClient |
34 | | - |
35 | | - __all__ += ["AsyncOperationsRestClient", "AsyncOperationsRestTransport"] |
36 | | -except ImportError: |
37 | | - # This import requires the `async_rest` extra. |
38 | | - # Don't raise an exception if `AsyncOperationsRestTransport` cannot be imported |
39 | | - # as other transports are still available. |
40 | | - pass |
| 51 | + |
| 52 | +from google.api_core.operations_v1.abstract_operations_client import ( # noqa: E402 |
| 53 | + AbstractOperationsClient, |
| 54 | +) |
| 55 | +from google.api_core.operations_v1.operations_async_client import ( # noqa: E402 |
| 56 | + OperationsAsyncClient, |
| 57 | +) |
| 58 | +from google.api_core.operations_v1.operations_client import ( # noqa: E402 |
| 59 | + OperationsClient, |
| 60 | +) |
| 61 | +from google.api_core.operations_v1.transports.rest import ( # noqa: E402 |
| 62 | + OperationsRestTransport, |
| 63 | +) |
| 64 | + |
| 65 | +if _has_async_rest: |
| 66 | + try: |
| 67 | + from google.api_core.operations_v1.transports.rest_asyncio import ( # noqa: E402, F401 |
| 68 | + AsyncOperationsRestTransport, |
| 69 | + ) |
| 70 | + from google.api_core.operations_v1.operations_rest_client_async import ( # noqa: E402, F401 |
| 71 | + AsyncOperationsRestClient, |
| 72 | + ) |
| 73 | + |
| 74 | + __all__.extend(["AsyncOperationsRestClient", "AsyncOperationsRestTransport"]) |
| 75 | + except ImportError: |
| 76 | + # Fallback for older python/environments when importlib find_spec succeeds but actual import fails |
| 77 | + pass |
0 commit comments