1818
1919import os
2020import 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
5255def _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