From 7d6d6fa102e662d0a59010e0184fbeebb9f4fa4d Mon Sep 17 00:00:00 2001 From: Shweta Sharma Date: Fri, 27 Oct 2017 19:32:35 +0530 Subject: [PATCH] Respecting default value in defined for attribute within attr class while structuring --- cattr/converters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cattr/converters.py b/cattr/converters.py index dc7f8b0f..20d8d569 100644 --- a/cattr/converters.py +++ b/cattr/converters.py @@ -283,12 +283,12 @@ def _structure_attr_from_dict(self, a, name, mapping): type_ = a.metadata.get(TYPE_METADATA_KEY) if type_ is None: # No type. - return mapping[name] + return mapping.get(name, a.default) if _is_union_type(type_): # This is a union. val = mapping.get(name, NOTHING) if NoneType in type_.__args__ and val is NOTHING: - return None + return a.default return self._structure_union(val, type_) return self._structure.dispatch(type_)(mapping.get(a.name), type_)