Skip to content

Commit be597dc

Browse files
Merge branch 'dataclass'
2 parents f15d776 + c7d7f79 commit be597dc

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

ags/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.3"
1+
__version__ = "0.3.1"
22

33

44
def _get_backend_for(path):

ags/_mapping.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def unlower(self, obj, surject):
357357
@dataclasses.dataclass
358358
class DataClass:
359359
cls: type
360-
fields: dict[str, typing.Any]
360+
fields: dict[str, Mapping]
361361

362362
def lower(self, obj, inject):
363363
if not dataclasses.is_dataclass(obj) or isinstance(obj, type):
@@ -371,9 +371,12 @@ def lower(self, obj, inject):
371371
def unlower(self, obj, surject):
372372
dobj = surject(obj, dict)
373373
d = {}
374-
for name, mapping in self.fields.items():
374+
for name, value in dobj.items():
375+
mapping = self.fields.get(name)
376+
if mapping is None:
377+
raise ValueError(f"invalid field: {name!r}")
375378
with context(f".{name}"):
376-
d[name] = mapping.unlower(dobj[name], surject)
379+
d[name] = mapping.unlower(value, surject)
377380
return self.cls(**d)
378381

379382

0 commit comments

Comments
 (0)