working on code
[bigint-presentation-code.git] / src / bigint_presentation_code / util.py
index 03eaeff9e91ca2b0ae6214031652f83f9ccc3863..423714a3304cbb1e05e16a009baffd9bbd45be4b 100644 (file)
@@ -26,13 +26,15 @@ class InternedMeta(ABCMeta):
         # type: (*Any, **Any) -> None
         super().__init__(*args, **kwargs)
         self.__INTERN_TABLE = {}  # type: dict[Any, Any]
+        self._InternedMeta__interned = False
 
     def __intern(self, value):
         # type: (_T) -> _T
+        if value._InternedMeta__interned:  # type: ignore
+            return value
         value = self.__INTERN_TABLE.setdefault(value, value)
-        if value.__dict__.get("_InternedMeta__interned", False):
+        if value._InternedMeta__interned:  # type: ignore
             return value
-        value.__dict__["_InternedMeta__interned"] = True
         hash_v = hash(value)
         value.__dict__["__hash__"] = lambda: hash_v
         old_eq = value.__eq__
@@ -40,9 +42,12 @@ class InternedMeta(ABCMeta):
         def __eq__(__o):
             # type: (_T) -> bool
             if value.__class__ is __o.__class__:
-                return value is __o
+                if (value._InternedMeta__interned and  # type: ignore
+                        __o._InternedMeta__interned):  # type: ignore
+                    return value is __o
             return old_eq(__o)
         value.__dict__["__eq__"] = __eq__
+        value.__dict__["_InternedMeta__interned"] = True
         return value
 
     def __call__(self, *args, **kwargs):