# 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__
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):