Skip to content

Commit 161448f

Browse files
author
David Cavazos
authored
chore: update type hints to comply with PEP-0585 (GoogleCloudPlatform#9974)
## Description Updates the type hints to comply with [PEP-0585](https://peps.python.org/pep-0585). The script covers most cases, but a handful still required manual intervention to normalize them. Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google. ## Checklist - [ ] I have followed [Sample Guidelines from AUTHORING_GUIDE.MD](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md) - [ ] README is updated to include [all relevant information](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#readme-file) - [ ] **Tests** pass: `nox -s py-3.9` (see [Test Environment Setup](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] **Lint** pass: `nox -s lint` (see [Test Environment Setup](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] These samples need a new **API enabled** in testing projects to pass (let us know which ones) - [ ] These samples need a new/updated **env vars** in testing projects set to pass (let us know which ones) - [ ] This sample adds a new sample directory, and I updated the [CODEOWNERS file](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/.github/CODEOWNERS) with the codeowners for this sample - [ ] This sample adds a new **Product API**, and I updated the [Blunderbuss issue/PR auto-assigner](https://togithub.com/GoogleCloudPlatform/python-docs-samples/blob/main/.github/blunderbuss.yml) with the codeowners for this sample - [ ] Please **merge** this PR for me once it is approved
1 parent 6a36fe3 commit 161448f

File tree

167 files changed

+1023
-441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+1023
-441
lines changed

appengine/flexible/storage/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# limitations under the License.
1414

1515
# [START gae_flex_storage_app]
16+
from __future__ import annotations
17+
1618
import logging
1719
import os
1820

appengine/flexible_python37_and_earlier/storage/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
# limitations under the License.
1414

1515
# [START gae_flex_storage_app]
16+
from __future__ import annotations
17+
1618
import logging
1719
import os
18-
from typing import Union
1920

2021
from flask import Flask, request
2122
from google.cloud import storage
@@ -68,7 +69,7 @@ def upload() -> str:
6869

6970

7071
@app.errorhandler(500)
71-
def server_error(e: Union[Exception, int]) -> str:
72+
def server_error(e: Exception | int) -> str:
7273
logging.exception('An error occurred during a request.')
7374
return """
7475
An internal error occurred: <pre>{}</pre>

batch/list/list_jobs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
# limitations under the License.
1414

1515
# [START batch_list_jobs]
16-
from typing import Iterable
16+
from __future__ import annotations
17+
18+
from collections.abc import Iterable
1719

1820
from google.cloud import batch_v1
1921

batch/list/list_tasks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
# limitations under the License.
1414

1515
# [START batch_list_tasks]
16-
from typing import Iterable
16+
from __future__ import annotations
17+
18+
from collections.abc import Iterable
1719

1820
from google.cloud import batch_v1
1921

batch/logs/read_job_logs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515

1616
# [START batch_job_logs]
17+
from __future__ import annotations
18+
1719
from typing import NoReturn
1820

1921
from google.cloud import batch_v1

batch/tests/test_basics.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from __future__ import annotations
15+
16+
from collections.abc import Callable
1417
import time
15-
from typing import Callable
1618
import uuid
1719

1820
from flaky import flaky

bigquery/remote-function/translate/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# limitations under the License.
1414

1515
# [START bigquery_remote_function_translation]
16-
from typing import List
16+
from __future__ import annotations
17+
1718

1819
import flask
1920
import functions_framework
@@ -89,8 +90,8 @@ def extract_project_from_caller(job: str) -> str:
8990

9091

9192
def translate_text(
92-
calls: List[str], project: str, target_language_code: str
93-
) -> List[str]:
93+
calls: list[str], project: str, target_language_code: str
94+
) -> list[str]:
9495
"""Translates the input text to specified language using Translation API.
9596
9697
Args:

cloud-sql/mysql/client-side-encryption/snippets/cloud_sql_connection_pool_test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
# See the License for the specific language governing permissions and
2727
# limitations under the License.
2828

29+
from __future__ import annotations
30+
2931
import os
30-
from typing import Dict
3132
import uuid
3233

3334
import pytest
@@ -40,7 +41,7 @@
4041

4142

4243
@pytest.fixture(name="conn_vars")
43-
def setup() -> Dict[str, str]:
44+
def setup() -> dict[str, str]:
4445
try:
4546
conn_vars = {}
4647
conn_vars["db_user"] = os.environ["MYSQL_USER"]
@@ -61,7 +62,7 @@ def setup() -> Dict[str, str]:
6162

6263
def test_init_tcp_connection_engine(
6364
capsys: pytest.CaptureFixture,
64-
conn_vars: Dict[str, str]) -> None:
65+
conn_vars: dict[str, str]) -> None:
6566

6667
init_tcp_connection_engine(
6768
db_user=conn_vars["db_user"],
@@ -76,7 +77,7 @@ def test_init_tcp_connection_engine(
7677

7778
def test_init_unix_connection_engine(
7879
capsys: pytest.CaptureFixture,
79-
conn_vars: Dict[str, str]) -> None:
80+
conn_vars: dict[str, str]) -> None:
8081

8182
init_unix_connection_engine(
8283
db_user=conn_vars["db_user"],
@@ -92,7 +93,7 @@ def test_init_unix_connection_engine(
9293

9394
def test_init_db(
9495
capsys: pytest.CaptureFixture,
95-
conn_vars: Dict[str, str]) -> None:
96+
conn_vars: dict[str, str]) -> None:
9697

9798
table_name = f"votes_{uuid.uuid4().hex}"
9899

cloud-sql/mysql/sqlalchemy/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
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 datetime
1618
import logging
1719
import os
18-
from typing import Dict
1920

2021
from flask import Flask, render_template, request, Response
2122

@@ -92,7 +93,7 @@ def cast_vote() -> Response:
9293

9394

9495
# get_index_context gets data required for rendering HTML application
95-
def get_index_context(db: sqlalchemy.engine.base.Engine) -> Dict:
96+
def get_index_context(db: sqlalchemy.engine.base.Engine) -> dict:
9697
votes = []
9798

9899
with db.connect() as conn:

cloud-sql/postgres/client-side-encryption/snippets/cloud_sql_connection_pool_test.py

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

15+
from __future__ import annotations
1516

1617
import os
17-
from typing import Dict
1818
import uuid
1919

2020
import pytest
@@ -27,7 +27,7 @@
2727

2828

2929
@pytest.fixture(name="conn_vars")
30-
def setup() -> Dict[str, str]:
30+
def setup() -> dict[str, str]:
3131
try:
3232
conn_vars = {}
3333
conn_vars["db_user"] = os.environ["POSTGRES_USER"]
@@ -48,7 +48,7 @@ def setup() -> Dict[str, str]:
4848

4949
def test_init_tcp_connection_engine(
5050
capsys: pytest.CaptureFixture,
51-
conn_vars: Dict[str, str]) -> None:
51+
conn_vars: dict[str, str]) -> None:
5252

5353
init_tcp_connection_engine(
5454
db_user=conn_vars["db_user"],
@@ -63,7 +63,7 @@ def test_init_tcp_connection_engine(
6363

6464
def test_init_unix_connection_engine(
6565
capsys: pytest.CaptureFixture,
66-
conn_vars: Dict[str, str]) -> None:
66+
conn_vars: dict[str, str]) -> None:
6767

6868
init_unix_connection_engine(
6969
db_user=conn_vars["db_user"],
@@ -79,7 +79,7 @@ def test_init_unix_connection_engine(
7979

8080
def test_init_db(
8181
capsys: pytest.CaptureFixture,
82-
conn_vars: Dict[str, str]) -> None:
82+
conn_vars: dict[str, str]) -> None:
8383

8484
table_name = f"votes_{uuid.uuid4().hex}"
8585

0 commit comments

Comments
 (0)