diff --git a/pytools/tag.py b/pytools/tag.py index d15131ff35fcadb9061c0eb8e397bc699f42983b..ac80314be4569f7e08d6f72a1fc98bee443ed11f 100644 --- a/pytools/tag.py +++ b/pytools/tag.py @@ -102,6 +102,15 @@ class DottedName: "start with double underscores") return cls(name_parts) + def __repr__(self) -> str: + return self.__class__.__name__ + repr(self.name_parts) + + def __eq__(self, other: object) -> bool: + if isinstance(other, DottedName): + return self.name_parts == other.name_parts + else: + return False + # }}} diff --git a/pytools/test/test_pytools.py b/pytools/test/test_pytools.py index 624b3c66822734f75fced0f682eb9ab4ca78a5ef..117823abfb7d8048d1a04a974bc2449a57736889 100644 --- a/pytools/test/test_pytools.py +++ b/pytools/test/test_pytools.py @@ -582,6 +582,15 @@ def test_tag(): with pytest.raises(ValueError): t4.without_tags(red_ribbon) + # Test DottedName comparison + from pytools.tag import DottedName + assert FairRibbon() == FairRibbon() + assert (FairRibbon().tag_name + == FairRibbon().tag_name + == DottedName(("test_pytools", "FairRibbon"))) + assert FairRibbon() != BlueRibbon() + assert FairRibbon().tag_name != BlueRibbon().tag_name + def test_unordered_hash(): import hashlib