Skip to content

Commit c72bc30

Browse files
committed
refactor: modernize type hints in feature gating helpers
1 parent f667db5 commit c72bc30

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

packages/google-api-core/google/api_core/_feature_gating_helpers.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818

1919
import os
2020
import warnings
21-
from typing import Any, Dict, Optional, Union
21+
from typing import Any
22+
23+
# We import ClientOptions for type hinting
24+
from google.api_core.client_options import ClientOptions
2225

2326
# Allowed truthy and falsy patterns for environment variables
2427
_TRUTHY_VALUES = ("y", "yes", "t", "true", "on", "1")
2528
_FALSY_VALUES = ("n", "no", "f", "false", "off", "0")
2629

2730

28-
def _strtobool(val: str) -> Optional[bool]:
31+
def _strtobool(val: str) -> bool | None:
2932
"""Convert a string representation of truth to a boolean."""
3033
clean_val = val.lower().strip()
3134
if not clean_val:
@@ -37,7 +40,7 @@ def _strtobool(val: str) -> Optional[bool]:
3740
raise ValueError(f"Invalid truth value: {val!r}")
3841

3942

40-
def _get_env_bool(name: str) -> Optional[bool]:
43+
def _get_env_bool(name: str) -> bool | None:
4144
"""Retrieve the boolean value of an environment variable."""
4245
val = os.getenv(name)
4346
if val is None:
@@ -50,7 +53,7 @@ def _get_env_bool(name: str) -> Optional[bool]:
5053

5154

5255
def _has_provider(
53-
*, configuration: Optional[Union[Dict[str, Any], Any]], feature_key: str
56+
*, configuration: ClientOptions | dict[str, Any] | None, feature_key: str
5457
) -> bool:
5558
"""Checks if a specific feature key is present and not None in configuration."""
5659
if configuration is None:
@@ -69,7 +72,7 @@ def resolve_feature_flags(
6972
*,
7073
env_var: str,
7174
feature_key: str,
72-
configuration: Optional[Union[Dict[str, Any], Any]] = None,
75+
configuration: ClientOptions | dict[str, Any] | None = None,
7376
) -> bool:
7477
"""Determines if a feature is enabled based on environment variables and configuration.
7578

0 commit comments

Comments
 (0)