Skip to content

Commit 7bc6f9d

Browse files
committed
feat: Add __str__ method to enum classes
1 parent 7d3ef9d commit 7bc6f9d

File tree

8 files changed

+49
-1
lines changed

8 files changed

+49
-1
lines changed

src/firebase_functions/https_fn.py

+6
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ class FunctionsErrorCode(str, _enum.Enum):
135135
Unrecoverable data loss or corruption.
136136
"""
137137

138+
def __str__(self) -> str:
139+
return self.value
140+
138141

139142
class _CanonicalErrorCodeName(str, _enum.Enum):
140143
"""The canonical error code name for a given error code."""
@@ -157,6 +160,9 @@ class _CanonicalErrorCodeName(str, _enum.Enum):
157160
UNAVAILABLE = "UNAVAILABLE"
158161
DATA_LOSS = "DATA_LOSS"
159162

163+
def __str__(self) -> str:
164+
return self.value
165+
160166

161167
@_dataclasses.dataclass(frozen=True)
162168
class _HttpErrorCode:

src/firebase_functions/logger.py

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class LogSeverity(str, _enum.Enum):
2424
ALERT = "ALERT"
2525
EMERGENCY = "EMERGENCY"
2626

27+
def __str__(self) -> str:
28+
return self.value
29+
2730

2831
class LogEntry(_typing.TypedDict):
2932
"""

src/firebase_functions/options.py

+15
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class VpcEgressSetting(str, _enum.Enum):
4141
PRIVATE_RANGES_ONLY = "PRIVATE_RANGES_ONLY"
4242
ALL_TRAFFIC = "ALL_TRAFFIC"
4343

44+
def __str__(self) -> str:
45+
return self.value
46+
4447

4548
class IngressSetting(str, _enum.Enum):
4649
"""What kind of traffic can access the function."""
@@ -49,6 +52,9 @@ class IngressSetting(str, _enum.Enum):
4952
ALLOW_INTERNAL_ONLY = "ALLOW_INTERNAL_ONLY"
5053
ALLOW_INTERNAL_AND_GCLB = "ALLOW_INTERNAL_AND_GCLB"
5154

55+
def __str__(self) -> str:
56+
return self.value
57+
5258

5359
@_dataclasses.dataclass(frozen=True)
5460
class CorsOptions:
@@ -88,6 +94,9 @@ class MemoryOption(int, _enum.Enum):
8894
GB_16 = 16 << 10
8995
GB_32 = 32 << 10
9096

97+
def __str__(self) -> str:
98+
return f"{self.value}MB"
99+
91100

92101
class SupportedRegion(str, _enum.Enum):
93102
"""
@@ -120,6 +129,9 @@ class SupportedRegion(str, _enum.Enum):
120129
US_WEST3 = "us-west3"
121130
US_WEST4 = "us-west4"
122131

132+
def __str__(self) -> str:
133+
return self.value
134+
123135

124136
@_dataclasses.dataclass(frozen=True)
125137
class RateLimits():
@@ -587,6 +599,9 @@ class AlertType(str, _enum.Enum):
587599
Performance threshold alerts.
588600
"""
589601

602+
def __str__(self) -> str:
603+
return self.value
604+
590605

591606
@_dataclasses.dataclass(frozen=True, kw_only=True)
592607
class FirebaseAlertOptions(EventHandlerOptions):

src/firebase_functions/params.py

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ class ResourceType(str, _enum.Enum):
168168
"""The type of resource that a picker should pick."""
169169
STORAGE_BUCKET = "storage.googleapis.com/Bucket"
170170

171+
def __str__(self) -> str:
172+
return self.value
173+
171174

172175
@_dataclasses.dataclass(frozen=True)
173176
class ResourceInput:

src/firebase_functions/private/path_pattern.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ def trim_param(param: str) -> str:
3737
_WILDCARD_CAPTURE_REGEX = re.compile(r"{[^/{}]+}", re.IGNORECASE)
3838

3939

40-
class SegmentName(Enum):
40+
class SegmentName(str, Enum):
4141
SEGMENT = "segment"
4242
SINGLE_CAPTURE = "single-capture"
4343
MULTI_CAPTURE = "multi-capture"
4444

45+
def __str__(self) -> str:
46+
return self.value
47+
4548

4649
class PathSegment:
4750
"""

src/firebase_functions/private/util.py

+6
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ class OnCallTokenState(_enum.Enum):
187187
The token is invalid.
188188
"""
189189

190+
def __str__(self) -> str:
191+
return self.value
192+
190193

191194
@_dataclasses.dataclass()
192195
class _OnCallTokenVerification:
@@ -388,6 +391,9 @@ class PrecisionTimestamp(_enum.Enum):
388391

389392
SECONDS = "SECONDS"
390393

394+
def __str__(self) -> str:
395+
return self.value
396+
391397

392398
def get_precision_timestamp(time: str) -> PrecisionTimestamp:
393399
"""Return a bool which indicates if the timestamp is in nanoseconds"""

src/firebase_functions/remote_config_fn.py

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class ConfigUpdateOrigin(str, _enum.Enum):
7575
The update came from the Firebase Admin Node SDK.
7676
"""
7777

78+
def __str__(self) -> str:
79+
return self.value
80+
7881

7982
class ConfigUpdateType(str, _enum.Enum):
8083
"""
@@ -102,6 +105,9 @@ class ConfigUpdateType(str, _enum.Enum):
102105
A rollback to a previous Remote Config template.
103106
"""
104107

108+
def __str__(self) -> str:
109+
return self.value
110+
105111

106112
@_dataclasses.dataclass(frozen=True)
107113
class ConfigUpdateData:

src/firebase_functions/test_lab_fn.py

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class TestState(str, _enum.Enum):
6363
The test matrix was not run because the provided inputs are not valid.
6464
"""
6565

66+
def __str__(self) -> str:
67+
return self.value
68+
6669

6770
class OutcomeSummary(str, _enum.Enum):
6871
"""
@@ -101,6 +104,9 @@ class OutcomeSummary(str, _enum.Enum):
101104
All tests were skipped.
102105
"""
103106

107+
def __str__(self) -> str:
108+
return self.value
109+
104110

105111
@_dataclasses.dataclass(frozen=True)
106112
class ResultStorage:

0 commit comments

Comments
 (0)