diff --git a/pytools/tag.py b/pytools/tag.py index afb9557b..be620365 100644 --- a/pytools/tag.py +++ b/pytools/tag.py @@ -276,8 +276,12 @@ def tagged(self, tags: ToTagSetConvertible) -> Self: :arg tags: An instance of :class:`~pytools.tag.Tag` or an iterable with instances therein. """ - return self._with_new_tags( - tags=check_tag_uniqueness(normalize_tags(tags) | self.tags)) + normalized = normalize_tags(tags) + new_tags = check_tag_uniqueness(normalized | self.tags) + if normalized <= self.tags: + return self + else: + return self._with_new_tags(tags=new_tags) def without_tags(self, tags: ToTagSetConvertible, verify_existence: bool = True @@ -297,7 +301,10 @@ def without_tags(self, if verify_existence and len(new_tags) > len(self.tags) - len(to_remove): raise ValueError("A tag specified for removal was not present.") - return self._with_new_tags(tags=check_tag_uniqueness(new_tags)) + if to_remove & self.tags: + return self._with_new_tags(tags=check_tag_uniqueness(new_tags)) + else: + return self @memoize_method def tags_of_type(self, tag_t: type[TagT]) -> frozenset[TagT]: