From ad0f53e1dac15482e279f4318eff1dd0c29404f4 Mon Sep 17 00:00:00 2001
From: Matthias Diener <matthias.diener@gmail.com>
Date: Tue, 21 Nov 2023 11:29:52 -0600
Subject: [PATCH] Tag: implement eq, repr for DottedName (#190)

* Tag: implement eq, repr for DottedName

* flake8
---
 pytools/tag.py               | 9 +++++++++
 pytools/test/test_pytools.py | 9 +++++++++
 2 files changed, 18 insertions(+)

diff --git a/pytools/tag.py b/pytools/tag.py
index d15131f..ac80314 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 624b3c6..117823a 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
-- 
GitLab