Skip to content

Commit 48dde7b

Browse files
chore: add TYPE_CHECKING for imports (#56)
1 parent 4b7af83 commit 48dde7b

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

google/cloud/alloydb/connector/client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import logging
16-
from typing import List, Optional, Tuple
18+
from typing import List, Optional, Tuple, TYPE_CHECKING
1719

1820
import aiohttp
1921
from cryptography.hazmat.primitives import serialization
20-
from cryptography.hazmat.primitives.asymmetric import rsa
2122

22-
from google.auth.credentials import Credentials
2323
from google.auth.transport.requests import Request
2424
from google.cloud.alloydb.connector.utils import _create_certificate_request
2525
from google.cloud.alloydb.connector.version import __version__ as version
2626

27+
if TYPE_CHECKING:
28+
from cryptography.hazmat.primitives.asymmetric import rsa
29+
from google.auth.credentials import Credentials
30+
2731
USER_AGENT: str = f"alloydb-python-connector/{version}"
2832
API_VERSION: str = "v1beta"
2933

google/cloud/alloydb/connector/connector.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,25 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import asyncio
1618
from functools import partial
1719
from threading import Thread
1820
from types import TracebackType
19-
from typing import Any, Dict, Optional, Type
21+
from typing import Any, Dict, Optional, Type, TYPE_CHECKING
2022

2123
from cryptography.hazmat.primitives.asymmetric import rsa
2224

2325
from google.auth import default
24-
from google.auth.credentials import Credentials, with_scopes_if_required
26+
from google.auth.credentials import with_scopes_if_required
2527
from google.cloud.alloydb.connector.client import AlloyDBClient
2628
from google.cloud.alloydb.connector.instance import Instance
2729
import google.cloud.alloydb.connector.pg8000 as pg8000
2830

31+
if TYPE_CHECKING:
32+
from google.auth.credentials import Credentials
33+
2934

3035
class Connector:
3136
"""A class to configure and create connections to Cloud SQL instances.

google/cloud/alloydb/connector/instance.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import asyncio
1618
import logging
17-
import ssl
18-
from typing import Tuple
19-
20-
from cryptography.hazmat.primitives.asymmetric import rsa
19+
from typing import Tuple, TYPE_CHECKING
2120

22-
from google.cloud.alloydb.connector.client import AlloyDBClient
2321
from google.cloud.alloydb.connector.exceptions import RefreshError
2422
from google.cloud.alloydb.connector.rate_limiter import AsyncRateLimiter
2523
from google.cloud.alloydb.connector.refresh import (
@@ -28,6 +26,11 @@
2826
RefreshResult,
2927
)
3028

29+
if TYPE_CHECKING:
30+
import ssl
31+
from cryptography.hazmat.primitives.asymmetric import rsa
32+
from google.cloud.alloydb.connector.client import AlloyDBClient
33+
3134
logger = logging.getLogger(name=__name__)
3235

3336

google/cloud/alloydb/connector/refresh.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import asyncio
1618
from datetime import datetime
1719
import logging
1820
import ssl
1921
from tempfile import TemporaryDirectory
20-
from typing import List, Tuple
22+
from typing import List, Tuple, TYPE_CHECKING
2123

2224
from cryptography import x509
23-
from cryptography.hazmat.primitives.asymmetric import rsa
2425

2526
from google.cloud.alloydb.connector.utils import _write_to_file
2627

28+
if TYPE_CHECKING:
29+
from cryptography.hazmat.primitives.asymmetric import rsa
30+
2731
logger = logging.getLogger(name=__name__)
2832

2933
# _refresh_buffer is the amount of time before a refresh's result expires

google/cloud/alloydb/connector/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import List, Tuple
15+
from __future__ import annotations
16+
17+
from typing import List, Tuple, TYPE_CHECKING
1618

1719
from cryptography import x509
1820
from cryptography.hazmat.primitives import hashes, serialization
19-
from cryptography.hazmat.primitives.asymmetric import rsa
2021
from cryptography.x509.oid import NameOID
2122

23+
if TYPE_CHECKING:
24+
from cryptography.hazmat.primitives.asymmetric import rsa
25+
2226

2327
def _write_to_file(
2428
dir_path: str, cert_chain: List[str], client_cert: str, key: rsa.RSAPrivateKey

0 commit comments

Comments
 (0)