diff --git a/attmap/_version.py b/attmap/_version.py index 8e377d6..8e2394f 100644 --- a/attmap/_version.py +++ b/attmap/_version.py @@ -1 +1 @@ -__version__ = "0.12.5" +__version__ = "0.12.6" diff --git a/attmap/attmap.py b/attmap/attmap.py index 2ee7706..1edc05e 100644 --- a/attmap/attmap.py +++ b/attmap/attmap.py @@ -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) + self.__dict__[key] = self._final_for_store(key, value) def __eq__(self, other): # TODO: check for equality across classes? @@ -80,10 +80,11 @@ def same_type(obj1, obj2, typenames=None): # have nonidentical labels. return False - def _final_for_store(self, v): + def _final_for_store(self, k, v): """ Before storing a value, apply any desired transformation. + :param hashable k: key for which to store value :param object v: value to potentially transform before storing :return object: finalized value """ diff --git a/attmap/ordattmap.py b/attmap/ordattmap.py index f2f9523..ddc636f 100644 --- a/attmap/ordattmap.py +++ b/attmap/ordattmap.py @@ -41,7 +41,7 @@ def __getitem__(self, item): def __setitem__(self, key, value): """ Support hook for value transformation before storage. """ - super(OrdAttMap, self).__setitem__(key, self._final_for_store(value)) + super(OrdAttMap, self).__setitem__(key, self._final_for_store(key, value)) def __delitem__(self, key): """ Make unmapped key deletion unexceptional. """ diff --git a/docs/changelog.md b/docs/changelog.md index fc4ce49..d4b940a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,9 @@ # Changelog +## [0.12.6] - 2019-06-24 +### Added +- Hook in value storage finalization for use of the key, not just the value + ## [0.12.5] - 2019-06-06 ### Changed - By default, represent empty `Mapping` value as `null` in YAML rendition.