def mutating_method ( func ) : def wrapper ( self , * __args , * * __kwargs ) : old_mutable = self . _mutable self . _mutable = True try : # Call the wrapped function return func ( self , * __args , * * __kwargs ) finally : self . _mutable = old_mutable return wrapper
python ensure objects passed into a function are immutable
Decorator for methods that are allowed to modify immutable objects
def mutating_method(func):
    """Decorator for methods that are allowed to modify immutable objects"""
    def wrapper(self, *__args, **__kwargs):
        old_mutable = self._mutable
        self._mutable = True
        try:
            # Call the wrapped function
            return func(self, *__args, **__kwargs)
        finally:
            self._mutable = old_mutable
    return wrapper