Skip to content
Merged
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
9 changes: 6 additions & 3 deletions ags/_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def unlower(self, obj, surject):
@dataclasses.dataclass
class DataClass:
cls: type
fields: dict[str, typing.Any]
fields: dict[str, Mapping]

def lower(self, obj, inject):
if not dataclasses.is_dataclass(obj) or isinstance(obj, type):
Expand All @@ -371,9 +371,12 @@ def lower(self, obj, inject):
def unlower(self, obj, surject):
dobj = surject(obj, dict)
d = {}
for name, mapping in self.fields.items():
for name, value in dobj.items():
mapping = self.fields.get(name)
if mapping is None:
raise ValueError(f"invalid field: {name!r}")
with context(f".{name}"):
d[name] = mapping.unlower(dobj[name], surject)
d[name] = mapping.unlower(value, surject)
return self.cls(**d)


Expand Down
Loading