Skip to content

Commit 9469c9d

Browse files
authored
Merge pull request #62 from pepkit/dev
hook for use of key in value storage finalization
2 parents 660e279 + 222736a commit 9469c9d

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

attmap/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.12.5"
1+
__version__ = "0.12.6"

attmap/attmap.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __setitem__(self, key, value, finalize=True):
4343
"""
4444
# TODO: consider enforcement of type constraint, that value of different
4545
# type may not overwrite existing.
46-
self.__dict__[key] = self._final_for_store(value)
46+
self.__dict__[key] = self._final_for_store(key, value)
4747

4848
def __eq__(self, other):
4949
# TODO: check for equality across classes?
@@ -80,10 +80,11 @@ def same_type(obj1, obj2, typenames=None):
8080
# have nonidentical labels.
8181
return False
8282

83-
def _final_for_store(self, v):
83+
def _final_for_store(self, k, v):
8484
"""
8585
Before storing a value, apply any desired transformation.
8686
87+
:param hashable k: key for which to store value
8788
:param object v: value to potentially transform before storing
8889
:return object: finalized value
8990
"""

attmap/ordattmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __getitem__(self, item):
4141

4242
def __setitem__(self, key, value):
4343
""" Support hook for value transformation before storage. """
44-
super(OrdAttMap, self).__setitem__(key, self._final_for_store(value))
44+
super(OrdAttMap, self).__setitem__(key, self._final_for_store(key, value))
4545

4646
def __delitem__(self, key):
4747
""" Make unmapped key deletion unexceptional. """

docs/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [0.12.6] - 2019-06-24
4+
### Added
5+
- Hook in value storage finalization for use of the key, not just the value
6+
37
## [0.12.5] - 2019-06-06
48
### Changed
59
- By default, represent empty `Mapping` value as `null` in YAML rendition.

0 commit comments

Comments
 (0)