Skip to content

Commit a73f347

Browse files
committed
chore(gapic): clean up Python version guards and imports in templates
1 parent e25391c commit a73f347

4 files changed

Lines changed: 9 additions & 26 deletions

File tree

packages/gapic-generator/gapic/ads-templates/%namespace/%name/%version/__init__.py.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ from {{package_path}} import gapic_version as package_version
1111
__version__ = package_version.__version__
1212

1313

14-
if sys.version_info < (3, 8):
15-
raise ImportError('This module requires Python 3.8 or later.')
14+
if sys.version_info < (3, 10):
15+
raise ImportError('This module requires Python 3.10 or later.')
1616

1717

1818
_lazy_type_to_package_map = {

packages/gapic-generator/gapic/ads-templates/%namespace/%name/__init__.py.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import importlib
66
import sys
77

88

9-
if sys.version_info < (3, 8):
10-
raise ImportError('This module requires Python 3.8 or later.')
9+
if sys.version_info < (3, 10):
10+
raise ImportError('This module requires Python 3.10 or later.')
1111

1212

1313
_lazy_type_to_package_map = {

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/__init__.py.j2

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ import sys
1010

1111
__version__ = package_version.__version__
1212

13-
if sys.version_info >= (3, 8): # pragma: NO COVER
14-
from importlib import metadata
15-
else: # pragma: NO COVER
16-
# TODO(https://github.com/googleapis/python-api-core/issues/835): Remove
17-
# this code path once we drop support for Python 3.7
18-
import importlib_metadata as metadata
13+
from importlib import metadata
1914

2015
{# Import subpackages. -#}
2116
{% for subpackage, _ in api.subpackages|dictsort %}
@@ -65,20 +60,12 @@ else: # pragma: NO COVER
6560

6661
_py_version_str = sys.version.split()[0]
6762
_package_label = "{{package_path}}"
68-
if sys.version_info < (3, 9):
63+
if sys.version_info < (3, 10):
6964
warnings.warn("You are using a non-supported Python version " +
7065
f"({_py_version_str}). Google will not post any further " +
7166
f"updates to {_package_label} supporting this Python version. " +
7267
"Please upgrade to the latest Python version, or at " +
73-
f"least to Python 3.9, and then update {_package_label}.",
74-
FutureWarning)
75-
if sys.version_info[:2] == (3, 9):
76-
warnings.warn(f"You are using a Python version ({_py_version_str}) " +
77-
f"which Google will stop supporting in {_package_label} in " +
78-
"January 2026. Please " +
79-
"upgrade to the latest Python version, or at " +
80-
"least to Python 3.10, before then, and " +
81-
f"then update {_package_label}.",
68+
f"least to Python 3.10, and then update {_package_label}.",
8269
FutureWarning)
8370

8471
def parse_version_to_tuple(version_string: str):

packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ import os
1010
{% if api.all_method_settings.values()|map(attribute="auto_populated_fields", default=[])|list %}
1111
import re
1212
{% endif %}
13-
# try/except added for compatibility with python < 3.8
14-
try:
15-
from unittest import mock
16-
from unittest.mock import AsyncMock # pragma: NO COVER
17-
except ImportError: # pragma: NO COVER
18-
import mock
13+
from unittest import mock
14+
from unittest.mock import AsyncMock
1915

2016
import grpc
2117
from grpc.experimental import aio

0 commit comments

Comments
 (0)