ImmutableMap.update

This commit is contained in:
Jakub Warmuz 2015-03-24 18:32:58 +00:00
parent b24487a14b
commit 5c40daaf1c
No known key found for this signature in database
GPG key ID: 2A7BAD3A489B52EA

View file

@ -57,6 +57,12 @@ class ImmutableMap(collections.Mapping, collections.Hashable):
for slot in self.__slots__:
object.__setattr__(self, slot, kwargs.pop(slot))
def update(self, **kwargs):
"""Return updated map."""
items = dict(self)
items.update(kwargs)
return type(self)(**items)
def __getitem__(self, key):
try:
return getattr(self, key)