Skip to content

Commit 44ceca3

Browse files
committed
Merge branch 'main' into shuowei-test-render-mode-warning
2 parents 2eff2a2 + 8ed6b71 commit 44ceca3

2 files changed

Lines changed: 60 additions & 17 deletions

File tree

.github/workflows/import-profiler.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@ jobs:
3232
TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }}
3333
TEST_TYPE: import_profile
3434
PY_VERSION: "3.15"
35+
# Workaround: Allows libcst to compile on Python 3.15+ while PyO3 catches up
36+
PYO3_USE_ABI3_FORWARD_COMPATIBILITY: "1"
3537
run: |
3638
ci/run_conditional_tests.sh

packages/google-api-core/google/api_core/operations_v1/__init__.py

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,68 @@
1414

1515
"""Package for interacting with the google.longrunning.operations meta-API."""
1616

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+
try:
21+
_has_async_rest = (
22+
importlib.util.find_spec("google.auth.aio.transport.sessions") is not None
23+
)
24+
except ModuleNotFoundError:
25+
_has_async_rest = False
26+
27+
# PEP 0810: Explicit Lazy Imports
28+
# Python 3.15+ natively intercepts and defers these imports.
29+
# Developers can disable this behavior and force eager imports.
30+
# For more information, see:
31+
# https://docs.python.org/3.15/library/sys.html#sys.set_lazy_imports_filter
32+
# Older Python versions safely ignore this variable.
33+
# NOTE: We statically define all modules here (including async ones) to ensure
34+
# static analysis tools (mypy, pyright, Ruff) can easily parse them. If async
35+
# support is not present, the imports are ignored, making their presence safe.
36+
__lazy_modules__: Set[str] = {
37+
"google.api_core.operations_v1.abstract_operations_client",
38+
"google.api_core.operations_v1.operations_async_client",
39+
"google.api_core.operations_v1.operations_client",
40+
"google.api_core.operations_v1.transports.rest",
41+
"google.api_core.operations_v1.transports.rest_asyncio",
42+
"google.api_core.operations_v1.operations_rest_client_async",
43+
}
2144

2245
__all__ = [
2346
"AbstractOperationsClient",
2447
"OperationsAsyncClient",
2548
"OperationsClient",
26-
"OperationsRestTransport"
49+
"OperationsRestTransport",
2750
]
2851

29-
try:
30-
from google.api_core.operations_v1.transports.rest_asyncio import (
31-
AsyncOperationsRestTransport,
32-
)
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
52+
53+
from google.api_core.operations_v1.abstract_operations_client import ( # noqa: E402
54+
AbstractOperationsClient,
55+
)
56+
from google.api_core.operations_v1.operations_async_client import ( # noqa: E402
57+
OperationsAsyncClient,
58+
)
59+
from google.api_core.operations_v1.operations_client import ( # noqa: E402
60+
OperationsClient,
61+
)
62+
from google.api_core.operations_v1.transports.rest import ( # noqa: E402
63+
OperationsRestTransport,
64+
)
65+
66+
if _has_async_rest:
67+
try:
68+
# On Python 3.15+, PEP 0810 lazy loading means these imports will succeed
69+
# instantly (returning a lazy proxy). Any actual ImportErrors (e.g., due to
70+
# missing aiohttp/auth dependencies) are deferred until the proxies are accessed.
71+
from google.api_core.operations_v1.transports.rest_asyncio import ( # noqa: E402, F401
72+
AsyncOperationsRestTransport,
73+
)
74+
from google.api_core.operations_v1.operations_rest_client_async import ( # noqa: E402, F401
75+
AsyncOperationsRestClient,
76+
)
77+
78+
__all__.extend(["AsyncOperationsRestClient", "AsyncOperationsRestTransport"])
79+
except ImportError:
80+
# Fallback for older python/environments when importlib find_spec succeeds but actual import fails
81+
pass

0 commit comments

Comments
 (0)