walker: simplify path handling
authorDmitry Selyutin <ghostmansd@gmail.com>
Tue, 20 Jun 2023 20:34:33 +0000 (23:34 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 20 Jun 2023 20:34:36 +0000 (23:34 +0300)
src/mdis/walker.py

index 578284e4c9b9667ceb44f759e200fd9f92a25834..4d1c33dbcf39bc3bd630c9ef7ec83611bf76b74b 100644 (file)
@@ -28,38 +28,32 @@ class PartId(enum.Enum):
 
 class Walker(dispatcher.Dispatcher, metaclass=WalkerMeta):
     @dispatcher.Hook(tuple, list)
-    def dispatch_ordered_sequence(self, instance, path=()):
+    def dispatch_ordered_sequence(self, instance):
         for (index, item) in enumerate(instance):
-            part = (PartId.Index, index)
-            parts = (path + (part,))
-            yield (item, parts)
-            yield from self(item, path=parts)
+            yield (item, instance, index, PartId.Index)
+            yield from self(item)
 
     @dispatcher.Hook(set, frozenset)
-    def dispatch_unordered_sequence(self, instance, path=[]):
+    def dispatch_unordered_sequence(self, instance):
         for item in instance:
-            part = (PartId.Hash, item)
-            parts = (path + (part,))
-            yield (item, parts)
-            yield from self(item, path=parts)
+            yield (item, instance, item, PartId.Hash)
+            yield from self(item)
 
     @dispatcher.Hook(dataclasses.is_dataclass)
-    def dispatch_dataclass(self, instance, path=[]):
+    def dispatch_dataclass(self, instance):
         for field in dataclasses.fields(instance):
             key = field.name
             value = getattr(instance, key)
-            part = (PartId.Attribute, key)
-            parts = (path + (part,))
-            yield (value, parts)
-            yield from self(value, path=parts)
+            yield (value, instance, key, PartId.Attribute)
+            yield from self(value)
 
     @dispatcher.Hook(dict)
-    def dispatch_mapping(self, instance, path=[]):
+    def dispatch_mapping(self, instance):
         for (key, value) in instance.items():
-            part = (PartId.Index, key)
-            parts = (path + (part,))
-            yield (value, parts)
-            yield from self(value, path=parts)
+            yield (key, instance, key, PartId.Hash)
+            yield from self(key)
+            yield (value, instance, key, PartId.Index)
+            yield from self(value)
 
     @dispatcher.Hook(object)
     def dispatch_object(self, instance, path=()):