From 8f77bedc482a85482b3afa52f2aee03e28552be5 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sat, 10 Jun 2023 22:37:30 +0300 Subject: [PATCH] insndb/core: switch Fields to Dict class --- src/openpower/insndb/core.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/openpower/insndb/core.py b/src/openpower/insndb/core.py index 7ec4788f..d0425ff8 100644 --- a/src/openpower/insndb/core.py +++ b/src/openpower/insndb/core.py @@ -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 = ( -- 2.30.2