lambda is a singleton (hashable) therefore can be safely set as the
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 10 Jun 2023 22:42:32 +0000 (23:42 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 10 Jun 2023 22:42:32 +0000 (23:42 +0100)
default option to a function parameter
https://bugs.libre-soc.org/show_bug.cgi?id=1094#c89

src/openpower/insndb/core.py
src/openpower/insndb/db.py

index 3c0e68bf5c0d69ba430582afdfdf33c072d17196..21f5cc482a68b8c48dbfbae340a373ee7442a442 100644 (file)
@@ -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:
@@ -146,10 +140,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:
@@ -221,7 +212,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()
@@ -229,10 +220,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)
 
 
@@ -882,7 +873,7 @@ class Operands(Dict, datatype=object):
         return super().__init__(mapping)
 
     @walkmethod
-    def walk(clsself, match=None):
+    def walk(clsself, match=lambda _: True):
         for (key, (cls, pairs)) in clsself.items():
             yield ("/".join((key, "class")), cls.__name__)
             for (subkey, value) in pairs:
@@ -3851,10 +3842,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:
index c7788f8a08c58545c215eadb95a4fa37771b1626..fa5eb267ea7ae14f442183b260c2580b16d56a80 100644 (file)
@@ -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):