all: simplify walking
authorDmitry Selyutin <ghostmansd@gmail.com>
Mon, 4 Dec 2023 17:53:23 +0000 (20:53 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Mon, 4 Dec 2023 17:53:23 +0000 (20:53 +0300)
src/mdis/dispatcher.py
src/mdis/visitor.py
src/mdis/walker.py

index a8794d4d53e7098c412c462c2d8a24102503e52b..0ab54a097e7bef6a52f8efccb3264c03d39533d3 100644 (file)
@@ -122,8 +122,8 @@ class Dispatcher(metaclass=DispatcherMeta):
                 break
         if hook is None:
             hook = self.__class__.dispatch()
-        return hook(self, node, *args, **kwargs)
+        return hook(self, node)
 
     @Hook(object)
-    def dispatch_object(self, node, *_, **__):
+    def dispatch_object(self, node):
         raise NotImplementedError()
index 3342684137e791765ba2e23b7053256454b6ce43..b9c205687eb5717d272b4057d37579fae6c9f527 100644 (file)
@@ -15,12 +15,12 @@ class VisitorMeta(dispatcher.DispatcherMeta):
 
 class Visitor(dispatcher.Dispatcher, metaclass=VisitorMeta):
     @dispatcher.Hook(object)
-    def dispatch_object(self, node, *_, **__):
+    def dispatch_object(self, node):
         return node
 
 
 class ContextVisitor(Visitor):
     @dispatcher.Hook(object)
     @contextlib.contextmanager
-    def dispatch_object(self, node, *_, **__):
+    def dispatch_object(self, node):
         yield node
index 894357dc6279d850052436d3c045b463de7d2b7f..6d316ac61999029ed9acd194e8f2a7bc41db5c3d 100644 (file)
@@ -46,28 +46,30 @@ class HashPath(GenericPath):
 
 class Walker(dispatcher.Dispatcher, metaclass=WalkerMeta):
     @dispatcher.Hook(tuple, list)
-    def dispatch_ordered_sequence(self, node, *_, **__):
+    def dispatch_ordered_sequence(self, node):
         for (index, item) in enumerate(node):
-            yield (item, node, index, IndexPath)
+            yield index
+            yield item
 
     @dispatcher.Hook(set, frozenset)
-    def dispatch_unordered_sequence(self, node, *_, **__):
+    def dispatch_unordered_sequence(self, node):
         for item in node:
-            yield (item, node, item, HashPath)
+            yield item
 
     @dispatcher.Hook(dataclasses.is_dataclass)
-    def dispatch_dataclass(self, node, *_, **__):
+    def dispatch_dataclass(self, node):
         for field in dataclasses.fields(node):
             key = field.name
             value = getattr(node, key)
-            yield (value, node, key, AttributePath)
+            yield key
+            yield value
 
     @dispatcher.Hook(dict)
-    def dispatch_mapping(self, node, *_, **__):
+    def dispatch_mapping(self, node):
         for (key, value) in node.items():
-            yield (key, node, key, HashPath)
-            yield (value, node, key, IndexPath)
+            yield key
+            yield value
 
     @dispatcher.Hook(object)
-    def dispatch_object(self, node, *_, **__):
+    def dispatch_object(self, node):
         yield from ()