Skip to content

feat: Add __str__ method to enum classes #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/firebase_functions/https_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/firebase_functions/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class LogSeverity(str, _enum.Enum):
ALERT = "ALERT"
EMERGENCY = "EMERGENCY"

def __str__(self) -> str:
return self.value


class LogEntry(_typing.TypedDict):
"""
Expand Down
15 changes: 15 additions & 0 deletions src/firebase_functions/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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:
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions src/firebase_functions/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion src/firebase_functions/private/path_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
6 changes: 6 additions & 0 deletions src/firebase_functions/private/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ class OnCallTokenState(_enum.Enum):
The token is invalid.
"""

def __str__(self) -> str:
return self.value


@_dataclasses.dataclass()
class _OnCallTokenVerification:
Expand Down Expand Up @@ -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"""
Expand Down
6 changes: 6 additions & 0 deletions src/firebase_functions/remote_config_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions src/firebase_functions/test_lab_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand Down