Skip to content

Commit

Permalink
Respecting default value in defined for attribute within attr class w…
Browse files Browse the repository at this point in the history
…hile structuring
  • Loading branch information
Shweta Sharma committed Oct 27, 2017
1 parent 02d9da0 commit 7d6d6fa
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cattr/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_)

Expand Down

0 comments on commit 7d6d6fa

Please sign in to comment.