Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit a188534

Browse files
committed
removed ParsedVersion
1 parent f7f67ab commit a188534

8 files changed

Lines changed: 26 additions & 42 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ from .types.{{ proto.module_name }} import {{ enum.name }}
4747
{% endfor %}
4848
{% endfor %}
4949

50-
ParsedVersion = Tuple[int, ...]
51-
5250
if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
5351
{# TODO(api_core): remove `type:ignore` below when minimum version of api_core makes the else clause unnecessary. #}
5452
api_core.check_python_version("{{package_path}}") # type: ignore
@@ -84,7 +82,7 @@ else: # pragma: NO COVER
8482
f"then update {_package_label}.",
8583
FutureWarning)
8684

87-
def parse_version_to_tuple(version_string: str) -> ParsedVersion: # pragma: NO COVER
85+
def parse_version_to_tuple(version_string: str):
8886
"""Safely converts a semantic version string to a comparable tuple of integers.
8987
Example: "4.25.8" -> (4, 25, 8)
9088
Ignores non-numeric parts and handles common version formats.

tests/integration/goldens/asset/google/cloud/asset_v1/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@
110110
from .types.assets import TimeWindow
111111
from .types.assets import VersionedResource
112112

113-
ParsedVersion = Tuple[int, ...]
114-
115113
if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
116114
api_core.check_python_version("google.cloud.asset_v1") # type: ignore
117115
api_core.check_dependency_versions("google.cloud.asset_v1") # type: ignore

tests/integration/goldens/credentials/google/iam/credentials_v1/__init__.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,6 @@
4141
from .types.common import SignJwtRequest
4242
from .types.common import SignJwtResponse
4343

44-
ParsedVersion = Tuple[int, ...]
45-
46-
def parse_version_to_tuple(version_string: str) -> ParsedVersion: # pragma: NO COVER
47-
"""Safely converts a semantic version string to a comparable tuple of integers.
48-
Example: "4.25.8" -> (4, 25, 8)
49-
Ignores non-numeric parts and handles common version formats.
50-
Args:
51-
version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
52-
Returns:
53-
Tuple of integers for the parsed version string.
54-
"""
55-
parts = []
56-
for part in version_string.split("."):
57-
try:
58-
parts.append(int(part))
59-
except ValueError:
60-
# If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
61-
# This is a simplification compared to 'packaging.parse_version', but sufficient
62-
# for comparing strictly numeric semantic versions.
63-
break
64-
return tuple(parts)
65-
6644
if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
6745
api_core.check_python_version("google.iam.credentials_v1") # type: ignore
6846
api_core.check_dependency_versions("google.iam.credentials_v1") # type: ignore
@@ -91,6 +69,26 @@ def parse_version_to_tuple(version_string: str) -> ParsedVersion: # pragma: NO
9169
f"then update {_package_label}.",
9270
FutureWarning)
9371

72+
def parse_version_to_tuple(version_string: str):
73+
"""Safely converts a semantic version string to a comparable tuple of integers.
74+
Example: "4.25.8" -> (4, 25, 8)
75+
Ignores non-numeric parts and handles common version formats.
76+
Args:
77+
version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
78+
Returns:
79+
Tuple of integers for the parsed version string.
80+
"""
81+
parts = []
82+
for part in version_string.split("."):
83+
try:
84+
parts.append(int(part))
85+
except ValueError:
86+
# If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
87+
# This is a simplification compared to 'packaging.parse_version', but sufficient
88+
# for comparing strictly numeric semantic versions.
89+
break
90+
return tuple(parts)
91+
9492
def _get_version(dependency_name):
9593
try:
9694
version_string: str = metadata.version(dependency_name)

tests/integration/goldens/eventarc/google/cloud/eventarc_v1/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@
7070
from .types.trigger import Transport
7171
from .types.trigger import Trigger
7272

73-
ParsedVersion = Tuple[int, ...]
74-
7573
if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
7674
api_core.check_python_version("google.cloud.eventarc_v1") # type: ignore
7775
api_core.check_dependency_versions("google.cloud.eventarc_v1") # type: ignore
@@ -100,7 +98,7 @@
10098
f"then update {_package_label}.",
10199
FutureWarning)
102100

103-
def parse_version_to_tuple(version_string: str) -> ParsedVersion: # pragma: NO COVER
101+
def parse_version_to_tuple(version_string: str):
104102
"""Safely converts a semantic version string to a comparable tuple of integers.
105103
Example: "4.25.8" -> (4, 25, 8)
106104
Ignores non-numeric parts and handles common version formats.

tests/integration/goldens/logging/google/cloud/logging_v2/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@
113113
from .types.logging_metrics import LogMetric
114114
from .types.logging_metrics import UpdateLogMetricRequest
115115

116-
ParsedVersion = Tuple[int, ...]
117-
118116
if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
119117
api_core.check_python_version("google.cloud.logging_v2") # type: ignore
120118
api_core.check_dependency_versions("google.cloud.logging_v2") # type: ignore
@@ -143,7 +141,7 @@
143141
f"then update {_package_label}.",
144142
FutureWarning)
145143

146-
def parse_version_to_tuple(version_string: str) -> ParsedVersion: # pragma: NO COVER
144+
def parse_version_to_tuple(version_string: str):
147145
"""Safely converts a semantic version string to a comparable tuple of integers.
148146
Example: "4.25.8" -> (4, 25, 8)
149147
Ignores non-numeric parts and handles common version formats.

tests/integration/goldens/logging_internal/google/cloud/logging_v2/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@
113113
from .types.logging_metrics import LogMetric
114114
from .types.logging_metrics import UpdateLogMetricRequest
115115

116-
ParsedVersion = Tuple[int, ...]
117-
118116
if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
119117
api_core.check_python_version("google.cloud.logging_v2") # type: ignore
120118
api_core.check_dependency_versions("google.cloud.logging_v2") # type: ignore
@@ -143,7 +141,7 @@
143141
f"then update {_package_label}.",
144142
FutureWarning)
145143

146-
def parse_version_to_tuple(version_string: str) -> ParsedVersion: # pragma: NO COVER
144+
def parse_version_to_tuple(version_string: str):
147145
"""Safely converts a semantic version string to a comparable tuple of integers.
148146
Example: "4.25.8" -> (4, 25, 8)
149147
Ignores non-numeric parts and handles common version formats.

tests/integration/goldens/redis/google/cloud/redis_v1/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@
6060
from .types.cloud_redis import WeeklyMaintenanceWindow
6161
from .types.cloud_redis import ZoneMetadata
6262

63-
ParsedVersion = Tuple[int, ...]
64-
6563
if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
6664
api_core.check_python_version("google.cloud.redis_v1") # type: ignore
6765
api_core.check_dependency_versions("google.cloud.redis_v1") # type: ignore
@@ -90,7 +88,7 @@
9088
f"then update {_package_label}.",
9189
FutureWarning)
9290

93-
def parse_version_to_tuple(version_string: str) -> ParsedVersion: # pragma: NO COVER
91+
def parse_version_to_tuple(version_string: str):
9492
"""Safely converts a semantic version string to a comparable tuple of integers.
9593
Example: "4.25.8" -> (4, 25, 8)
9694
Ignores non-numeric parts and handles common version formats.

tests/integration/goldens/redis_selective/google/cloud/redis_v1/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
from .types.cloud_redis import UpdateInstanceRequest
4848
from .types.cloud_redis import WeeklyMaintenanceWindow
4949

50-
ParsedVersion = Tuple[int, ...]
51-
5250
if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
5351
api_core.check_python_version("google.cloud.redis_v1") # type: ignore
5452
api_core.check_dependency_versions("google.cloud.redis_v1") # type: ignore
@@ -77,7 +75,7 @@
7775
f"then update {_package_label}.",
7876
FutureWarning)
7977

80-
def parse_version_to_tuple(version_string: str) -> ParsedVersion: # pragma: NO COVER
78+
def parse_version_to_tuple(version_string: str):
8179
"""Safely converts a semantic version string to a comparable tuple of integers.
8280
Example: "4.25.8" -> (4, 25, 8)
8381
Ignores non-numeric parts and handles common version formats.

0 commit comments

Comments
 (0)