diff --git a/royalnet/alchemist/update.py b/royalnet/alchemist/update.py index f77eea9e..fc513637 100644 --- a/royalnet/alchemist/update.py +++ b/royalnet/alchemist/update.py @@ -7,10 +7,32 @@ class Updatable: def update(self, **kwargs): """Set attributes from the kwargs, ignoring non-existant key/columns.""" for key, value in kwargs.items(): + if value is DoNotUpdate: + continue if hasattr(self, key): setattr(self, key, value) def set(self, **kwargs): """Set attributes from the kwargs, without checking for non-existant key/columns.""" for key, value in kwargs.items(): + if value is DoNotUpdate: + continue setattr(self, key, value) + + +class DoNotUpdateType: + """ + A type, similar to NoneType, used to mark fields that should be skipped in update and set operations. + """ + __slots__ = () + + +DoNotUpdate = DoNotUpdateType() +"""The constant instance of the DoNotUpdateType.""" + + +__all__ = ( + "Updatable", + "DoNotUpdateType", + "DoNotUpdate", +)