class Node:
@walkmethod
- def walk(clsself, match=lambda _: True):
+ def walk(clsself, match=None):
yield from ()
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
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:
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:
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()
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)
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:
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: