From 364db02680db1a6e7d4e493c1ff84af7551159a7 Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Wed, 15 Jul 2026 16:26:56 +0000 Subject: [PATCH 1/6] feat: implement PEP 0810 lazy loading in operations_v1 --- .../google/api_core/operations_v1/__init__.py | 69 ++++++++++++++----- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/packages/google-api-core/google/api_core/operations_v1/__init__.py b/packages/google-api-core/google/api_core/operations_v1/__init__.py index 4db32a4cb0af..8a0c4159f5fd 100644 --- a/packages/google-api-core/google/api_core/operations_v1/__init__.py +++ b/packages/google-api-core/google/api_core/operations_v1/__init__.py @@ -14,27 +14,64 @@ """Package for interacting with the google.longrunning.operations meta-API.""" -from google.api_core.operations_v1.abstract_operations_client import AbstractOperationsClient -from google.api_core.operations_v1.operations_async_client import OperationsAsyncClient -from google.api_core.operations_v1.operations_client import OperationsClient -from google.api_core.operations_v1.transports.rest import OperationsRestTransport +import importlib.util +from typing import Set + +_has_async_rest = ( + importlib.util.find_spec("google.auth.aio.transport.sessions") is not None +) + +# PEP 0810: Explicit Lazy Imports +# Python 3.15+ natively intercepts and defers these imports. +# Developers can disable this behavior and force eager imports. +# For more information, see: +# https://docs.python.org/3.15/library/sys.html#sys.set_lazy_imports_filter +# Older Python versions safely ignore this variable. +__lazy_modules__: Set[str] = { + "google.api_core.operations_v1.abstract_operations_client", + "google.api_core.operations_v1.operations_async_client", + "google.api_core.operations_v1.operations_client", + "google.api_core.operations_v1.transports.rest", +} __all__ = [ "AbstractOperationsClient", "OperationsAsyncClient", "OperationsClient", - "OperationsRestTransport" + "OperationsRestTransport", ] -try: - from google.api_core.operations_v1.transports.rest_asyncio import ( - AsyncOperationsRestTransport, +if _has_async_rest: + __lazy_modules__.update( + { + "google.api_core.operations_v1.transports.rest_asyncio", + "google.api_core.operations_v1.operations_rest_client_async", + } ) - from google.api_core.operations_v1.operations_rest_client_async import AsyncOperationsRestClient - - __all__ += ["AsyncOperationsRestClient", "AsyncOperationsRestTransport"] -except ImportError: - # This import requires the `async_rest` extra. - # Don't raise an exception if `AsyncOperationsRestTransport` cannot be imported - # as other transports are still available. - pass + +from google.api_core.operations_v1.abstract_operations_client import ( # noqa: E402 + AbstractOperationsClient, +) +from google.api_core.operations_v1.operations_async_client import ( # noqa: E402 + OperationsAsyncClient, +) +from google.api_core.operations_v1.operations_client import ( # noqa: E402 + OperationsClient, +) +from google.api_core.operations_v1.transports.rest import ( # noqa: E402 + OperationsRestTransport, +) + +if _has_async_rest: + try: + from google.api_core.operations_v1.transports.rest_asyncio import ( # noqa: E402, F401 + AsyncOperationsRestTransport, + ) + from google.api_core.operations_v1.operations_rest_client_async import ( # noqa: E402, F401 + AsyncOperationsRestClient, + ) + + __all__.extend(["AsyncOperationsRestClient", "AsyncOperationsRestTransport"]) + except ImportError: + # Fallback for older python/environments when importlib find_spec succeeds but actual import fails + pass From c3790bf350f6e13bb60da02a0b37782cb999c5b5 Mon Sep 17 00:00:00 2001 From: Heba Alazzeh <137334116+hebaalazzeh@users.noreply.github.com> Date: Wed, 15 Jul 2026 09:32:00 -0700 Subject: [PATCH 2/6] Update packages/google-api-core/google/api_core/operations_v1/__init__.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- .../google/api_core/operations_v1/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/google-api-core/google/api_core/operations_v1/__init__.py b/packages/google-api-core/google/api_core/operations_v1/__init__.py index 8a0c4159f5fd..99b6f7606910 100644 --- a/packages/google-api-core/google/api_core/operations_v1/__init__.py +++ b/packages/google-api-core/google/api_core/operations_v1/__init__.py @@ -17,9 +17,12 @@ import importlib.util from typing import Set -_has_async_rest = ( - importlib.util.find_spec("google.auth.aio.transport.sessions") is not None -) +try: + _has_async_rest = ( + importlib.util.find_spec("google.auth.aio.transport.sessions") is not None + ) +except ModuleNotFoundError: + _has_async_rest = False # PEP 0810: Explicit Lazy Imports # Python 3.15+ natively intercepts and defers these imports. From af231a0c2ef41c69bf2354ed2be77ac703068f5b Mon Sep 17 00:00:00 2001 From: Heba Alazzeh <137334116+hebaalazzeh@users.noreply.github.com> Date: Wed, 15 Jul 2026 10:28:04 -0700 Subject: [PATCH 3/6] Update packages/google-api-core/google/api_core/operations_v1/__init__.py Co-authored-by: Anthonios Partheniou --- .../google/api_core/operations_v1/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/google-api-core/google/api_core/operations_v1/__init__.py b/packages/google-api-core/google/api_core/operations_v1/__init__.py index 99b6f7606910..ee32641d1048 100644 --- a/packages/google-api-core/google/api_core/operations_v1/__init__.py +++ b/packages/google-api-core/google/api_core/operations_v1/__init__.py @@ -30,11 +30,16 @@ # For more information, see: # https://docs.python.org/3.15/library/sys.html#sys.set_lazy_imports_filter # Older Python versions safely ignore this variable. +# NOTE: We statically define all modules here (including async ones) to ensure +# static analysis tools (mypy, pyright, Ruff) can easily parse them. If async +# support is not present, the imports are ignored, making their presence safe. __lazy_modules__: Set[str] = { "google.api_core.operations_v1.abstract_operations_client", "google.api_core.operations_v1.operations_async_client", "google.api_core.operations_v1.operations_client", "google.api_core.operations_v1.transports.rest", + "google.api_core.operations_v1.transports.rest_asyncio", + "google.api_core.operations_v1.operations_rest_client_async", } __all__ = [ From e3a181a613230cf4cf9792e21b6f7f502cf642a7 Mon Sep 17 00:00:00 2001 From: Heba Alazzeh <137334116+hebaalazzeh@users.noreply.github.com> Date: Wed, 15 Jul 2026 10:28:13 -0700 Subject: [PATCH 4/6] Update packages/google-api-core/google/api_core/operations_v1/__init__.py Co-authored-by: Anthonios Partheniou --- .../google-api-core/google/api_core/operations_v1/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/google-api-core/google/api_core/operations_v1/__init__.py b/packages/google-api-core/google/api_core/operations_v1/__init__.py index ee32641d1048..2c469cbcba30 100644 --- a/packages/google-api-core/google/api_core/operations_v1/__init__.py +++ b/packages/google-api-core/google/api_core/operations_v1/__init__.py @@ -72,6 +72,9 @@ if _has_async_rest: try: + # On Python 3.15+, PEP 0810 lazy loading means these imports will succeed + # instantly (returning a lazy proxy). Any actual ImportErrors (e.g., due to + # missing aiohttp/auth dependencies) are deferred until the proxies are accessed. from google.api_core.operations_v1.transports.rest_asyncio import ( # noqa: E402, F401 AsyncOperationsRestTransport, ) From 0d7fd9b97bf410420e9ccc9aa3d19ff47af4ac6b Mon Sep 17 00:00:00 2001 From: Heba Alazzeh <137334116+hebaalazzeh@users.noreply.github.com> Date: Wed, 15 Jul 2026 10:30:54 -0700 Subject: [PATCH 5/6] Apply suggestion from @parthea Co-authored-by: Anthonios Partheniou --- .../google/api_core/operations_v1/__init__.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packages/google-api-core/google/api_core/operations_v1/__init__.py b/packages/google-api-core/google/api_core/operations_v1/__init__.py index 2c469cbcba30..66a67fd1f648 100644 --- a/packages/google-api-core/google/api_core/operations_v1/__init__.py +++ b/packages/google-api-core/google/api_core/operations_v1/__init__.py @@ -49,13 +49,6 @@ "OperationsRestTransport", ] -if _has_async_rest: - __lazy_modules__.update( - { - "google.api_core.operations_v1.transports.rest_asyncio", - "google.api_core.operations_v1.operations_rest_client_async", - } - ) from google.api_core.operations_v1.abstract_operations_client import ( # noqa: E402 AbstractOperationsClient, From c449c3f08a32fc7b967a149e366577c96696d88e Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Wed, 15 Jul 2026 17:47:56 +0000 Subject: [PATCH 6/6] fix: resolve trailing whitespace lint issues in operations_v1 --- .../google/api_core/operations_v1/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/google-api-core/google/api_core/operations_v1/__init__.py b/packages/google-api-core/google/api_core/operations_v1/__init__.py index 66a67fd1f648..71b079b8a18d 100644 --- a/packages/google-api-core/google/api_core/operations_v1/__init__.py +++ b/packages/google-api-core/google/api_core/operations_v1/__init__.py @@ -30,7 +30,7 @@ # For more information, see: # https://docs.python.org/3.15/library/sys.html#sys.set_lazy_imports_filter # Older Python versions safely ignore this variable. -# NOTE: We statically define all modules here (including async ones) to ensure +# NOTE: We statically define all modules here (including async ones) to ensure # static analysis tools (mypy, pyright, Ruff) can easily parse them. If async # support is not present, the imports are ignored, making their presence safe. __lazy_modules__: Set[str] = { @@ -65,8 +65,8 @@ if _has_async_rest: try: - # On Python 3.15+, PEP 0810 lazy loading means these imports will succeed - # instantly (returning a lazy proxy). Any actual ImportErrors (e.g., due to + # On Python 3.15+, PEP 0810 lazy loading means these imports will succeed + # instantly (returning a lazy proxy). Any actual ImportErrors (e.g., due to # missing aiohttp/auth dependencies) are deferred until the proxies are accessed. from google.api_core.operations_v1.transports.rest_asyncio import ( # noqa: E402, F401 AsyncOperationsRestTransport,