Skip to content

Commit

Permalink
Merge pull request pepkit#62 from pepkit/dev
Browse files Browse the repository at this point in the history
hook for use of key in value storage finalization
  • Loading branch information
vreuter committed Jun 24, 2019
2 parents 660e279 + 222736a commit 9469c9d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion attmap/_version.py
@@ -1 +1 @@
__version__ = "0.12.5"
__version__ = "0.12.6"
5 changes: 3 additions & 2 deletions attmap/attmap.py
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)
self.__dict__[key] = self._final_for_store(key, value)

def __eq__(self, other):
# TODO: check for equality across classes?
Expand Down Expand Up @@ -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
"""
Expand Down
2 changes: 1 addition & 1 deletion attmap/ordattmap.py
Expand Up @@ -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. """
Expand Down
4 changes: 4 additions & 0 deletions 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.
Expand Down

0 comments on commit 9469c9d

Please sign in to comment.