From 3a6b2708f9c29297f0110eb5fb4a919cdca60940 Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Fri, 26 Jan 2024 13:21:59 -0800 Subject: [PATCH] fix: add legacy imports to preserve backwards compatibility --- google/api_core/retry/__init__.py | 24 ++++++++++----------- tests/unit/retry/test_retry_imports.py | 29 +++++++++++++------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/google/api_core/retry/__init__.py b/google/api_core/retry/__init__.py index 32f276594..7402563ae 100644 --- a/google/api_core/retry/__init__.py +++ b/google/api_core/retry/__init__.py @@ -31,18 +31,18 @@ # The following imports are for backwards compatibility with https://github.com/googleapis/python-api-core/blob/4d7d2edee2c108d43deb151e6e0fdceb56b73275/google/api_core/retry.py # # TODO: Revert these imports on the next major version release (https://github.com/googleapis/python-api-core/issues/576) -import datetime -import functools -import logging -import random -import sys -import time -import inspect -import warnings -from typing import Any, Callable, TypeVar, TYPE_CHECKING -from google.api_core import datetime_helpers -from google.api_core import exceptions -from google.auth import exceptions as auth_exceptions +import datetime # noqa: F401 +import functools # noqa: F401 +import logging # noqa: F401 +import random # noqa: F401 +import sys # noqa: F401 +import time # noqa: F401 +import inspect # noqa: F401 +import warnings # noqa: F401 +from typing import Any, Callable, TypeVar, TYPE_CHECKING # noqa: F401 +from google.api_core import datetime_helpers # noqa: F401 +from google.api_core import exceptions # noqa: F401 +from google.auth import exceptions as auth_exceptions # noqa: F401 __all__ = ( "exponential_sleep_generator", diff --git a/tests/unit/retry/test_retry_imports.py b/tests/unit/retry/test_retry_imports.py index c967eb2a8..058982a10 100644 --- a/tests/unit/retry/test_retry_imports.py +++ b/tests/unit/retry/test_retry_imports.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest def test_legacy_imports_retry_unary_sync(): # TODO: Delete this test when when we revert these imports on the @@ -20,19 +19,19 @@ def test_legacy_imports_retry_unary_sync(): # (https://github.com/googleapis/python-api-core/issues/576) from google.api_core.retry import logging - from google.api_core.retry import datetime - from google.api_core.retry import functools - from google.api_core.retry import logging - from google.api_core.retry import random - from google.api_core.retry import sys - from google.api_core.retry import time - from google.api_core.retry import inspect - from google.api_core.retry import warnings - from google.api_core.retry import Any, Callable, TypeVar, TYPE_CHECKING - - from google.api_core.retry import datetime_helpers - from google.api_core.retry import exceptions - from google.api_core.retry import auth_exceptions + from google.api_core.retry import datetime # noqa: F401 + from google.api_core.retry import functools # noqa: F401 + from google.api_core.retry import logging # noqa: F401 + from google.api_core.retry import random # noqa: F401 + from google.api_core.retry import sys # noqa: F401 + from google.api_core.retry import time # noqa: F401 + from google.api_core.retry import inspect # noqa: F401 + from google.api_core.retry import warnings # noqa: F401 + from google.api_core.retry import Any, Callable, TypeVar, TYPE_CHECKING # noqa: F401 + + from google.api_core.retry import datetime_helpers # noqa: F401 + from google.api_core.retry import exceptions # noqa: F401 + from google.api_core.retry import auth_exceptions # noqa: F401 ### FIXME: How do we test the following, and how do we import it in __init__.py? # import google.api_core.retry.requests.exceptions @@ -43,7 +42,7 @@ def test_legacy_imports_retry_unary_async(): # next major version release # (https://github.com/googleapis/python-api-core/issues/576) - from google.api_core import retry_async + from google.api_core import retry_async # noqa: F401 ### FIXME: each of the following cause errors on the "retry_async" part: module not found # import google.api_core.retry_async.functools