Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: implement PEP 0810 lazy loading in operations_v1#17724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+58
−17
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
364db02
feat: implement PEP 0810 lazy loading in operations_v1
hebaalazzeh c3790bf
Update packages/google-api-core/google/api_core/operations_v1/__init_…
hebaalazzeh af231a0
Update packages/google-api-core/google/api_core/operations_v1/__init_…
hebaalazzeh e3a181a
Update packages/google-api-core/google/api_core/operations_v1/__init_…
hebaalazzeh 0d7fd9b
Apply suggestion from @parthea
hebaalazzeh c449c3f
fix: resolve trailing whitespace lint issues in operations_v1
hebaalazzeh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
75 changes: 58 additions & 17 deletions
75 packages/google-api-core/google/api_core/operations_v1/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -14,27 +14,68 @@ | ||
| """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 | ||
| 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. | ||
| # 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. | ||
| # 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__ = [ | ||
| "AbstractOperationsClient", | ||
| "OperationsAsyncClient", | ||
| "OperationsClient", | ||
| "OperationsRestTransport" | ||
| "OperationsRestTransport", | ||
| ] | ||
| try: | ||
| from google.api_core.operations_v1.transports.rest_asyncio import ( | ||
| AsyncOperationsRestTransport, | ||
| ) | ||
| 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: | ||
| # 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 | ||
hebaalazzeh marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| 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 | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.