From 7bc6f9dbc889a1f9e2dae0db6b523beb1a5da9a6 Mon Sep 17 00:00:00 2001 From: exaby73 Date: Mon, 26 Feb 2024 20:25:26 +0530 Subject: [PATCH] feat: Add __str__ method to enum classes --- src/firebase_functions/https_fn.py | 6 ++++++ src/firebase_functions/logger.py | 3 +++ src/firebase_functions/options.py | 15 +++++++++++++++ src/firebase_functions/params.py | 3 +++ src/firebase_functions/private/path_pattern.py | 5 ++++- src/firebase_functions/private/util.py | 6 ++++++ src/firebase_functions/remote_config_fn.py | 6 ++++++ src/firebase_functions/test_lab_fn.py | 6 ++++++ 8 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/firebase_functions/https_fn.py b/src/firebase_functions/https_fn.py index 45cdc5e..fed3973 100644 --- a/src/firebase_functions/https_fn.py +++ b/src/firebase_functions/https_fn.py @@ -135,6 +135,9 @@ class FunctionsErrorCode(str, _enum.Enum): Unrecoverable data loss or corruption. """ + def __str__(self) -> str: + return self.value + class _CanonicalErrorCodeName(str, _enum.Enum): """The canonical error code name for a given error code.""" @@ -157,6 +160,9 @@ class _CanonicalErrorCodeName(str, _enum.Enum): UNAVAILABLE = "UNAVAILABLE" DATA_LOSS = "DATA_LOSS" + def __str__(self) -> str: + return self.value + @_dataclasses.dataclass(frozen=True) class _HttpErrorCode: diff --git a/src/firebase_functions/logger.py b/src/firebase_functions/logger.py index cae47cc..9b61ea6 100644 --- a/src/firebase_functions/logger.py +++ b/src/firebase_functions/logger.py @@ -24,6 +24,9 @@ class LogSeverity(str, _enum.Enum): ALERT = "ALERT" EMERGENCY = "EMERGENCY" + def __str__(self) -> str: + return self.value + class LogEntry(_typing.TypedDict): """ diff --git a/src/firebase_functions/options.py b/src/firebase_functions/options.py index d0dc9c0..937a088 100644 --- a/src/firebase_functions/options.py +++ b/src/firebase_functions/options.py @@ -41,6 +41,9 @@ class VpcEgressSetting(str, _enum.Enum): PRIVATE_RANGES_ONLY = "PRIVATE_RANGES_ONLY" ALL_TRAFFIC = "ALL_TRAFFIC" + def __str__(self) -> str: + return self.value + class IngressSetting(str, _enum.Enum): """What kind of traffic can access the function.""" @@ -49,6 +52,9 @@ class IngressSetting(str, _enum.Enum): ALLOW_INTERNAL_ONLY = "ALLOW_INTERNAL_ONLY" ALLOW_INTERNAL_AND_GCLB = "ALLOW_INTERNAL_AND_GCLB" + def __str__(self) -> str: + return self.value + @_dataclasses.dataclass(frozen=True) class CorsOptions: @@ -88,6 +94,9 @@ class MemoryOption(int, _enum.Enum): GB_16 = 16 << 10 GB_32 = 32 << 10 + def __str__(self) -> str: + return f"{self.value}MB" + class SupportedRegion(str, _enum.Enum): """ @@ -120,6 +129,9 @@ class SupportedRegion(str, _enum.Enum): US_WEST3 = "us-west3" US_WEST4 = "us-west4" + def __str__(self) -> str: + return self.value + @_dataclasses.dataclass(frozen=True) class RateLimits(): @@ -587,6 +599,9 @@ class AlertType(str, _enum.Enum): Performance threshold alerts. """ + def __str__(self) -> str: + return self.value + @_dataclasses.dataclass(frozen=True, kw_only=True) class FirebaseAlertOptions(EventHandlerOptions): diff --git a/src/firebase_functions/params.py b/src/firebase_functions/params.py index dd97f6a..bc81900 100644 --- a/src/firebase_functions/params.py +++ b/src/firebase_functions/params.py @@ -168,6 +168,9 @@ class ResourceType(str, _enum.Enum): """The type of resource that a picker should pick.""" STORAGE_BUCKET = "storage.googleapis.com/Bucket" + def __str__(self) -> str: + return self.value + @_dataclasses.dataclass(frozen=True) class ResourceInput: diff --git a/src/firebase_functions/private/path_pattern.py b/src/firebase_functions/private/path_pattern.py index bcf8bf6..6bd36c3 100644 --- a/src/firebase_functions/private/path_pattern.py +++ b/src/firebase_functions/private/path_pattern.py @@ -37,11 +37,14 @@ def trim_param(param: str) -> str: _WILDCARD_CAPTURE_REGEX = re.compile(r"{[^/{}]+}", re.IGNORECASE) -class SegmentName(Enum): +class SegmentName(str, Enum): SEGMENT = "segment" SINGLE_CAPTURE = "single-capture" MULTI_CAPTURE = "multi-capture" + def __str__(self) -> str: + return self.value + class PathSegment: """ diff --git a/src/firebase_functions/private/util.py b/src/firebase_functions/private/util.py index 4a939af..09521fc 100644 --- a/src/firebase_functions/private/util.py +++ b/src/firebase_functions/private/util.py @@ -187,6 +187,9 @@ class OnCallTokenState(_enum.Enum): The token is invalid. """ + def __str__(self) -> str: + return self.value + @_dataclasses.dataclass() class _OnCallTokenVerification: @@ -388,6 +391,9 @@ class PrecisionTimestamp(_enum.Enum): SECONDS = "SECONDS" + def __str__(self) -> str: + return self.value + def get_precision_timestamp(time: str) -> PrecisionTimestamp: """Return a bool which indicates if the timestamp is in nanoseconds""" diff --git a/src/firebase_functions/remote_config_fn.py b/src/firebase_functions/remote_config_fn.py index 50d40cc..402fd98 100644 --- a/src/firebase_functions/remote_config_fn.py +++ b/src/firebase_functions/remote_config_fn.py @@ -75,6 +75,9 @@ class ConfigUpdateOrigin(str, _enum.Enum): The update came from the Firebase Admin Node SDK. """ + def __str__(self) -> str: + return self.value + class ConfigUpdateType(str, _enum.Enum): """ @@ -102,6 +105,9 @@ class ConfigUpdateType(str, _enum.Enum): A rollback to a previous Remote Config template. """ + def __str__(self) -> str: + return self.value + @_dataclasses.dataclass(frozen=True) class ConfigUpdateData: diff --git a/src/firebase_functions/test_lab_fn.py b/src/firebase_functions/test_lab_fn.py index 759d33d..15eb5ab 100644 --- a/src/firebase_functions/test_lab_fn.py +++ b/src/firebase_functions/test_lab_fn.py @@ -63,6 +63,9 @@ class TestState(str, _enum.Enum): The test matrix was not run because the provided inputs are not valid. """ + def __str__(self) -> str: + return self.value + class OutcomeSummary(str, _enum.Enum): """ @@ -101,6 +104,9 @@ class OutcomeSummary(str, _enum.Enum): All tests were skipped. """ + def __str__(self) -> str: + return self.value + @_dataclasses.dataclass(frozen=True) class ResultStorage: