Skip to content

Commit 5b245c6

Browse files
chore: update type hints to standard collections (#1183)
1 parent eb95a9d commit 5b245c6

17 files changed

+30
-36
lines changed

google/cloud/sql/connector/asyncpg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
"""
16+
1617
import ssl
1718
from typing import Any, TYPE_CHECKING
1819

google/cloud/sql/connector/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import asyncio
1818
import datetime
1919
import logging
20-
from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING
20+
from typing import Any, Optional, TYPE_CHECKING
2121

2222
import aiohttp
2323
from cryptography.hazmat.backends import default_backend
@@ -98,7 +98,7 @@ async def _get_metadata(
9898
project: str,
9999
region: str,
100100
instance: str,
101-
) -> Dict[str, Any]:
101+
) -> dict[str, Any]:
102102
"""Requests metadata from the Cloud SQL Instance
103103
and returns a dictionary containing the IP addresses and certificate
104104
authority of the Cloud SQL Instance.
@@ -113,7 +113,7 @@ async def _get_metadata(
113113
:type instance: str
114114
:param instance: A string representing the name of the instance.
115115
116-
:rtype: Dict[str: Union[Dict, str]]
116+
:rtype: dict[str: Union[dict, str]]
117117
:returns: Returns a dictionary containing a dictionary of all IP
118118
addresses and their type and a string representing the
119119
certificate authority.
@@ -161,7 +161,7 @@ async def _get_ephemeral(
161161
instance: str,
162162
pub_key: str,
163163
enable_iam_auth: bool = False,
164-
) -> Tuple[str, datetime.datetime]:
164+
) -> tuple[str, datetime.datetime]:
165165
"""Asynchronously requests an ephemeral certificate from the Cloud SQL Instance.
166166
167167
:type project: str

google/cloud/sql/connector/connection_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from dataclasses import dataclass
1818
import logging
1919
import ssl
20-
from typing import Any, Dict, Optional, TYPE_CHECKING
20+
from typing import Any, Optional, TYPE_CHECKING
2121

2222
from aiofiles.tempfile import TemporaryDirectory
2323

@@ -41,7 +41,7 @@ class ConnectionInfo:
4141
client_cert: str
4242
server_ca_cert: str
4343
private_key: bytes
44-
ip_addrs: Dict[str, Any]
44+
ip_addrs: dict[str, Any]
4545
database_version: str
4646
expiration: datetime.datetime
4747
context: Optional[ssl.SSLContext] = None

google/cloud/sql/connector/connector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import logging
2222
from threading import Thread
2323
from types import TracebackType
24-
from typing import Any, Dict, Optional, Tuple, Type, Union
24+
from typing import Any, Optional, Type, Union
2525

2626
import google.auth
2727
from google.auth.credentials import Credentials
@@ -133,8 +133,8 @@ def __init__(
133133
)
134134
# initialize dict to store caches, key is a tuple consisting of instance
135135
# connection name string and enable_iam_auth boolean flag
136-
self._cache: Dict[
137-
Tuple[str, bool], Union[RefreshAheadCache, LazyRefreshCache]
136+
self._cache: dict[
137+
tuple[str, bool], Union[RefreshAheadCache, LazyRefreshCache]
138138
] = {}
139139
self._client: Optional[CloudSQLClient] = None
140140

google/cloud/sql/connector/instance.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from datetime import timezone
2323
import logging
2424
import re
25-
from typing import Tuple
2625

2726
import aiohttp
2827

@@ -43,7 +42,7 @@
4342
CONN_NAME_REGEX = re.compile(("([^:]+(:[^:]+)?):([^:]+):([^:]+)"))
4443

4544

46-
def _parse_instance_connection_name(connection_name: str) -> Tuple[str, str, str]:
45+
def _parse_instance_connection_name(connection_name: str) -> tuple[str, str, str]:
4746
if CONN_NAME_REGEX.fullmatch(connection_name) is None:
4847
raise ValueError(
4948
"Arg `instance_connection_string` must have "

google/cloud/sql/connector/refresh_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import datetime
2222
import logging
2323
import random
24-
from typing import Any, Callable, List
24+
from typing import Any, Callable
2525

2626
import aiohttp
2727
from google.auth.credentials import Credentials
@@ -77,15 +77,15 @@ async def _is_valid(task: asyncio.Task) -> bool:
7777

7878
def _downscope_credentials(
7979
credentials: Credentials,
80-
scopes: List[str] = ["https://www.googleapis.com/auth/sqlservice.login"],
80+
scopes: list[str] = ["https://www.googleapis.com/auth/sqlservice.login"],
8181
) -> Credentials:
8282
"""Generate a down-scoped credential.
8383
8484
:type credentials: google.auth.credentials.Credentials
8585
:param credentials
8686
Credentials object used to generate down-scoped credentials.
8787
88-
:type scopes: List[str]
88+
:type scopes: list[str]
8989
:param scopes
9090
List of Google scopes to include in down-scoped credentials object.
9191

google/cloud/sql/connector/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414
limitations under the License.
1515
"""
1616

17-
from typing import Tuple
18-
1917
import aiofiles
2018
from cryptography.hazmat.backends import default_backend
2119
from cryptography.hazmat.primitives import serialization
2220
from cryptography.hazmat.primitives.asymmetric import rsa
2321

2422

25-
async def generate_keys() -> Tuple[bytes, str]:
23+
async def generate_keys() -> tuple[bytes, str]:
2624
"""A helper function to generate the private and public keys.
2725
2826
backend - The value specified is default_backend(). This is because the
@@ -61,7 +59,7 @@ async def generate_keys() -> Tuple[bytes, str]:
6159

6260
async def write_to_file(
6361
dir_path: str, serverCaCert: str, ephemeralCert: str, priv_key: bytes
64-
) -> Tuple[str, str, str]:
62+
) -> tuple[str, str, str]:
6563
"""
6664
Helper function to write the serverCaCert, ephemeral certificate and
6765
private key to .pem files in a given directory

tests/system/test_asyncpg_connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import asyncio
1818
import os
19-
from typing import Any, Tuple
19+
from typing import Any
2020

2121
import asyncpg
2222
import sqlalchemy
@@ -31,7 +31,7 @@ async def create_sqlalchemy_engine(
3131
password: str,
3232
db: str,
3333
refresh_strategy: str = "background",
34-
) -> Tuple[sqlalchemy.ext.asyncio.engine.AsyncEngine, Connector]:
34+
) -> tuple[sqlalchemy.ext.asyncio.engine.AsyncEngine, Connector]:
3535
"""Creates a connection pool for a Cloud SQL instance and returns the pool
3636
and the connector. Callers are responsible for closing the pool and the
3737
connector.
@@ -94,7 +94,7 @@ async def create_asyncpg_pool(
9494
password: str,
9595
db: str,
9696
refresh_strategy: str = "background",
97-
) -> Tuple[asyncpg.Pool, Connector]:
97+
) -> tuple[asyncpg.Pool, Connector]:
9898
"""Creates a native asyncpg connection pool for a Cloud SQL instance and
9999
returns the pool and the connector. Callers are responsible for closing the
100100
pool and the connector.

tests/system/test_asyncpg_iam_auth.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import asyncio
1818
import os
19-
from typing import Tuple
2019

2120
import asyncpg
2221
import sqlalchemy
@@ -30,7 +29,7 @@ async def create_sqlalchemy_engine(
3029
user: str,
3130
db: str,
3231
refresh_strategy: str = "background",
33-
) -> Tuple[sqlalchemy.ext.asyncio.engine.AsyncEngine, Connector]:
32+
) -> tuple[sqlalchemy.ext.asyncio.engine.AsyncEngine, Connector]:
3433
"""Creates a connection pool for a Cloud SQL instance and returns the pool
3534
and the connector. Callers are responsible for closing the pool and the
3635
connector.

tests/system/test_ip_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
"""
16+
1617
import os
1718
import uuid
1819

0 commit comments

Comments
 (0)