Skip to content

Commit 78574da

Browse files
Make ObjectStorageACL a StrEnum (#420)
1 parent 3aede44 commit 78574da

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

linode_api4/objects/object_storage.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional
12
from urllib import parse
23

34
from linode_api4.errors import UnexpectedResponseError
@@ -8,10 +9,11 @@
89
Property,
910
Region,
1011
)
12+
from linode_api4.objects.serializable import StrEnum
1113
from linode_api4.util import drop_null_keys
1214

1315

14-
class ObjectStorageACL:
16+
class ObjectStorageACL(StrEnum):
1517
PRIVATE = "private"
1618
PUBLIC_READ = "public-read"
1719
AUTHENTICATED_READ = "authenticated-read"
@@ -67,7 +69,7 @@ def make_instance(cls, id, client, parent_id=None, json=None):
6769

6870
def access_modify(
6971
self,
70-
acl: ObjectStorageACL = None,
72+
acl: Optional[ObjectStorageACL] = None,
7173
cors_enabled=None,
7274
):
7375
"""
@@ -109,7 +111,7 @@ def access_modify(
109111

110112
def access_update(
111113
self,
112-
acl: ObjectStorageACL = None,
114+
acl: Optional[ObjectStorageACL] = None,
113115
cors_enabled=None,
114116
):
115117
"""

linode_api4/objects/serializable.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import inspect
22
from dataclasses import dataclass
3+
from enum import Enum
34
from types import SimpleNamespace
45
from typing import (
56
Any,
@@ -223,3 +224,22 @@ def __delitem__(self, key):
223224

224225
def __len__(self):
225226
return len(vars(self))
227+
228+
229+
class StrEnum(str, Enum):
230+
"""
231+
Used for enums that are of type string, which is necessary
232+
for implicit JSON serialization.
233+
234+
NOTE: Replace this with StrEnum once Python 3.10 has been EOL'd.
235+
See: https://docs.python.org/3/library/enum.html#enum.StrEnum
236+
"""
237+
238+
def __new__(cls, *values):
239+
value = str(*values)
240+
member = str.__new__(cls, value)
241+
member._value_ = value
242+
return member
243+
244+
def __str__(self):
245+
return self._value_

0 commit comments

Comments
 (0)