From 983a58f055641f337880af0ca78c7de417d61ade Mon Sep 17 00:00:00 2001 From: Griatch Date: Thu, 18 Apr 2019 22:24:51 +0200 Subject: [PATCH] Make AttributeHandler.remove delete by category only as well --- evennia/typeclasses/attributes.py | 16 +++++++++++++--- evennia/typeclasses/tags.py | 8 +++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/evennia/typeclasses/attributes.py b/evennia/typeclasses/attributes.py index 9e16eb65c6..a6823221cf 100644 --- a/evennia/typeclasses/attributes.py +++ b/evennia/typeclasses/attributes.py @@ -601,14 +601,15 @@ class AttributeHandler(object): # Add new objects to m2m field all at once getattr(self.obj, self._m2m_fieldname).add(*new_attrobjs) - def remove(self, key, raise_exception=False, category=None, + def remove(self, key=None, raise_exception=False, category=None, accessing_obj=None, default_access=True): """ Remove attribute or a list of attributes from object. Args: - key (str or list): An Attribute key to remove or a list of keys. If - multiple keys, they must all be of the same `category`. + key (str or list, optional): An Attribute key to remove or a list of keys. If + multiple keys, they must all be of the same `category`. If None and + category is not given, remove all Attributes. raise_exception (bool, optional): If set, not finding the Attribute to delete will raise an exception instead of just quietly failing. @@ -625,7 +626,16 @@ class AttributeHandler(object): AttributeError: If `raise_exception` is set and no matching Attribute was found matching `key`. + Notes: + If neither key nor category is given, this acts as clear(). + """ + + if key is None: + self.clear(category=category, accessing_obj=accessing_obj, + default_access=default_access) + return + category = category.strip().lower() if category is not None else None for keystr in make_iter(key): diff --git a/evennia/typeclasses/tags.py b/evennia/typeclasses/tags.py index f97a4897cb..97e92e2a2f 100644 --- a/evennia/typeclasses/tags.py +++ b/evennia/typeclasses/tags.py @@ -309,13 +309,11 @@ class TagHandler(object): category (str, optional): The Tag category to limit the request to. Note that `None` is the valid, default category - Raises: - RuntimeError: If neither key nor category is specifed. + Notes: + If neither key nor category is specified, this acts + as .clear(). """ - if key is None and category is None: - raise RuntimeError("TagHandler.remove requires either key or category. " - "Use TagHandler.clear to remove all tags.") if not key: # only category self.clear(category=category)