Skip to content

Commit

Permalink
fix conditiional value insertion/update
Browse files Browse the repository at this point in the history
  • Loading branch information
vreuter committed May 17, 2019
1 parent c375b31 commit 27917a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions attmap/_att_map_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def add_entries(self, entries):
except AttributeError:
entries_iter = entries
for k, v in entries_iter:
self[k] = v if k not in self or not \
(isinstance(v, Mapping) and isinstance(self[k], AttMapLike)) \
self[k] = v if (k not in self or not isinstance(v, Mapping)
or not isinstance(self[k], Mapping)) \
else self[k].add_entries(v)
return self

Expand Down
5 changes: 3 additions & 2 deletions attmap/attmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __setitem__(self, key, value, finalize=True):
"""
# TODO: consider enforcement of type constraint, that value of different
# type may not overwrite existing.
self.__dict__[key] = self._final_for_store(value) if finalize else value
self.__dict__[key] = self._final_for_store(value)

def __eq__(self, other):
# TODO: check for equality across classes?
Expand Down Expand Up @@ -103,10 +103,11 @@ def _metamorph_maplike(self, m):
:return Mapping: a (perhaps more specialized) version of the given map
:raise TypeError: if the given value isn't a Mapping
"""
_LOGGER.debug("Transforming map-like: {}".format(m))
if not isinstance(m, Mapping):
raise TypeError("Cannot integrate a non-Mapping: {}\nType: {}".
format(m, type(m)))
return m.to_map() if isinstance(m, AttMapLike) else self._lower_type_bound(m.items())
return self._lower_type_bound(m.items())

def _new_empty_basic_map(self):
""" Return the empty collection builder for Mapping type simplification. """
Expand Down

0 comments on commit 27917a2

Please sign in to comment.