From: Luke Kenneth Casson Leighton Date: Sun, 11 Jun 2023 12:26:55 +0000 (+0100) Subject: temporary hack-revert, the original is now in branch "paths" X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fe4c26a52bf9cc651d49b196f76396fcb58f383f;p=openpower-isa.git temporary hack-revert, the original is now in branch "paths" Revert "lambda is a singleton (hashable) therefore can be safely set as the" This reverts commit adbe1ffb671b29c6854f951fa65d939895600fe6. --- diff --git a/src/openpower/insndb/core.py b/src/openpower/insndb/core.py index d19f92a5..69e0101b 100644 --- a/src/openpower/insndb/core.py +++ b/src/openpower/insndb/core.py @@ -71,7 +71,7 @@ class walkmethod: class Node: @walkmethod - def walk(clsself, match=lambda _: True): + def walk(clsself, match=None): yield from () @@ -83,7 +83,10 @@ class DataclassMeta(type): class Dataclass(Node, metaclass=DataclassMeta): @walkmethod - def walk(clsself, match=lambda _: True): + def walk(clsself, match=None): + if match is None: + match = lambda subnode: True + def field_type(field): return field.type @@ -104,7 +107,10 @@ class Tuple(Node, tuple): return super().__init_subclass__() @walkmethod - def walk(clsself, match=lambda _: True): + def walk(clsself, match=None): + if match is None: + match = lambda subnode: True + if isinstance(clsself, type): yield ("[]", clsself.__datatype) else: @@ -139,7 +145,10 @@ class Dict(Node, dict): raise NotImplementedError() @walkmethod - def walk(clsself, match=lambda _: True): + def walk(clsself, match=None): + if match is None: + match = lambda subnode: True + if isinstance(clsself, type): yield ("{}", clsself.__datatype) else: @@ -209,7 +218,7 @@ class visitormethod: return VisitorMethod(nodecls=self.__nodecls, method=method) -def walk(root, match=lambda _: True): +def walk(root, match=None): pairs = _collections.deque([root]) while pairs: (path, node) = pairs.popleft() @@ -217,10 +226,10 @@ def walk(root, match=lambda _: True): yield (path, node) -def visit(visitor, node, path="/", match=lambda _: True): +def visit(visitor, node, path="/"): with visitor(path=path, node=node): if isinstance(node, Node): - for (subpath, subnode) in node.walk(match=match): + for (subpath, subnode) in node.walk(): visit(visitor=visitor, path=subpath, node=subnode) @@ -870,7 +879,7 @@ class Operands(Dict, datatype=object): return super().__init__(mapping) @walkmethod - def walk(clsself, match=lambda _: True): + def walk(clsself, match=None): for (key, (cls, pairs)) in clsself.items(): yield ("/".join((key, "class")), cls.__name__) for (subkey, value) in pairs: @@ -3839,7 +3848,10 @@ class Database(Node): return super().__init__() @walkmethod - def walk(clsself, match=lambda _: True): + def walk(clsself, match=None): + if match is None: + match = lambda subnode: True + if isinstance(clsself, type): yield ("records", Records) else: diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index fa5eb267..c7788f8a 100644 --- a/src/openpower/insndb/db.py +++ b/src/openpower/insndb/db.py @@ -173,7 +173,7 @@ def main(): db = Database(find_wiki_dir()) (path, records) = next(db.walk(match=lambda pair: isinstance(pair, Records))) if not isinstance(visitor, InstructionVisitor): - match = lambda _: True + match = None else: insn = args.pop("insn") def match(record):