Skip to content

Commit d3a32bf

Browse files
committed
DI-26927 Corrected json to object modifications issues
1 parent 1d9107d commit d3a32bf

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

linode_api4/objects/monitor.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -344,24 +344,16 @@ class AlertDefinition(Base):
344344
def __init__(self, client, id, json=None):
345345
super().__init__(client, id, json)
346346

347-
# @property
348-
# def type(self):
349-
# return self._type
350-
351-
# @type.setter
352-
# def type(self, value):
353-
# self._type = value
354-
355347
def _populate(self, json):
356348
"""
357349
Populates this object with data from a JSON dictionary.
358350
"""
359351
for key, value in json.items():
360-
# Map "class" to "_class" because "class" is a reserved word in Python.
361-
if key == "class":
362-
setattr(self, "_class", value)
363-
else:
364-
setattr(self, key, value)
352+
#class and type are reserved words in Python.
353+
reserved = {"class": "_class", "type": "_type"}
354+
for json_key, json_value in json.items():
355+
attr = reserved.get(json_key, json_key)
356+
setattr(self, attr, json_value)
365357

366358

367359
@dataclass

0 commit comments

Comments
 (0)