insndb/core: switch Fields to Dict class
authorDmitry Selyutin <ghostmansd@gmail.com>
Sat, 10 Jun 2023 19:37:30 +0000 (22:37 +0300)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 22 Dec 2023 19:26:19 +0000 (19:26 +0000)
src/openpower/insndb/core.py

index 7ec4788f888aea9e25da17237976756d6f62555b..d0425ff8b968319875ba74d1050b275d399dea42 100644 (file)
@@ -743,7 +743,7 @@ class Section(Dataclass):
         return dataclass(cls, record, typemap=typemap, keymap=keymap)
 
 
-class Fields:
+class Fields(Dict, datatype=type("Bits", (Tuple,), {}, datatype=int)):
     def __init__(self, items):
         if isinstance(items, dict):
             items = items.items()
@@ -752,22 +752,16 @@ class Fields:
             (name, bitrange) = item
             return (name, tuple(bitrange.values()))
 
-        self.__mapping = dict(map(transform, items))
+        mapping = dict(map(transform, items))
 
-        return super().__init__()
+        return super().__init__(mapping)
 
-    def __repr__(self):
-        return repr(self.__mapping)
+    def __hash__(self):
+        return hash(tuple(sorted(self.items())))
 
     def __iter__(self):
         yield from self.__mapping.items()
 
-    def __contains__(self, key):
-        return self.__mapping.__contains__(key)
-
-    def __getitem__(self, key):
-        return self.__mapping.get(key, None)
-
 
 class Operands:
     __GPR_PAIRS = (