Author: Luke Kenneth Casson Leighton <lkcl@lkcl.net>
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
- def walk(clsself, match=None):
+ def walk(clsself, match=lambda _: True):
class Dataclass(Node, metaclass=DataclassMeta):
@walkmethod
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
def field_type(field):
return field.type
return super().__init_subclass__()
@walkmethod
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:
if isinstance(clsself, type):
yield ("[]", clsself.__datatype)
else:
raise NotImplementedError()
@walkmethod
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:
if isinstance(clsself, type):
yield ("{}", clsself.__datatype)
else:
return VisitorMethod(nodecls=self.__nodecls, method=method)
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()
pairs = _collections.deque([root])
while pairs:
(path, node) = pairs.popleft()
-def visit(visitor, node, path="/"):
+def visit(visitor, node, path="/", match=lambda _: True):
with visitor(path=path, node=node):
if isinstance(node, Node):
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)
visit(visitor=visitor, path=subpath, node=subnode)
return super().__init__()
@walkmethod
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:
if isinstance(clsself, type):
yield ("records", Records)
else:
db = Database(find_wiki_dir())
(path, records) = next(db.walk(match=lambda pair: isinstance(pair, Records)))
if not isinstance(visitor, InstructionVisitor):
db = Database(find_wiki_dir())
(path, records) = next(db.walk(match=lambda pair: isinstance(pair, Records)))
if not isinstance(visitor, InstructionVisitor):
else:
insn = args.pop("insn")
def match(record):
else:
insn = args.pop("insn")
def match(record):