From: Luke Kenneth Casson Leighton Date: Sun, 11 Jun 2023 12:33:48 +0000 (+0100) Subject: redo commit adbe1ffb671b29c6854f951fa65d939895600fe6 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bcab1f6;p=openpower-isa.git redo commit adbe1ffb671b29c6854f951fa65d939895600fe6 Author: Luke Kenneth Casson Leighton Date: Sat Jun 10 23:42:32 2023 +0100 lambda is a singleton (hashable) therefore can be safely set as the default option to a function parameter https://bugs.libre-soc.org/show_bug.cgi?id=1094#c89 --- diff --git a/src/openpower/insndb/core.py b/src/openpower/insndb/core.py index 2d0730c7..d77b2f0d 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=None): + def walk(clsself, match=lambda _: True): yield from () @@ -83,10 +83,7 @@ class DataclassMeta(type): class Dataclass(Node, metaclass=DataclassMeta): @walkmethod - def walk(clsself, match=None): - if match is None: - match = lambda subnode: True - + def walk(clsself, match=lambda _: True): def field_type(field): return field.type @@ -107,10 +104,7 @@ class Tuple(Node, tuple): return super().__init_subclass__() @walkmethod - def walk(clsself, match=None): - if match is None: - match = lambda subnode: True - + def walk(clsself, match=lambda _: True): if isinstance(clsself, type): yield ("[]", clsself.__datatype) else: @@ -145,10 +139,7 @@ class Dict(Node, dict): raise NotImplementedError() @walkmethod - def walk(clsself, match=None): - if match is None: - match = lambda subnode: True - + def walk(clsself, match=lambda _: True): if isinstance(clsself, type): yield ("{}", clsself.__datatype) else: @@ -218,7 +209,7 @@ class visitormethod: return VisitorMethod(nodecls=self.__nodecls, method=method) -def walk(root, match=None): +def walk(root, match=lambda _: True): pairs = _collections.deque([root]) while pairs: (path, node) = pairs.popleft() @@ -226,10 +217,10 @@ def walk(root, match=None): yield (path, node) -def visit(visitor, node, path="/"): +def visit(visitor, node, path="/", match=lambda _: True): with visitor(path=path, node=node): if isinstance(node, Node): - for (subpath, subnode) in node.walk(): + for (subpath, subnode) in node.walk(match=match): visit(visitor=visitor, path=subpath, node=subnode) @@ -3859,10 +3850,7 @@ class Database(Node): return super().__init__() @walkmethod - def walk(clsself, match=None): - if match is None: - match = lambda subnode: True - + def walk(clsself, match=lambda _: True): if isinstance(clsself, type): yield ("records", Records) else: diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index c7788f8a..fa5eb267 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 = None + match = lambda _: True else: insn = args.pop("insn") def match(record):