all: rename instance to node
authorDmitry Selyutin <ghostmansd@gmail.com>
Wed, 21 Jun 2023 20:48:42 +0000 (23:48 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Wed, 21 Jun 2023 21:25:46 +0000 (00:25 +0300)
src/mdis/dispatcher.py
src/mdis/visitor.py
src/mdis/walker.py

index 7add02773109ff52ffc880dedf4a779ef56abc18..c956e0c9e283b3c9eac78e13eb77fe179a6137b1 100644 (file)
@@ -33,9 +33,8 @@ class Hook(object):
 
     def __call__(self, call):
         class ConcreteHook(Hook):
-            def __call__(self, dispatcher, instance, *args, **kwargs):
-                return call(self=dispatcher, instance=instance,
-                    *args, **kwargs)
+            def __call__(self, dispatcher, node, *args, **kwargs):
+                return call(dispatcher, node, *args, **kwargs)
 
         return ConcreteHook(*tuple(self))
 
@@ -82,15 +81,15 @@ class DispatcherMeta(type):
 
 
 class Dispatcher(metaclass=DispatcherMeta):
-    def __call__(self, instance, *args, **kwargs):
-        for typeid in instance.__class__.__mro__:
+    def __call__(self, node, *args, **kwargs):
+        for typeid in node.__class__.__mro__:
             hook = self.__class__.dispatch(typeid=typeid)
             if hook is not None:
                 break
         if hook is None:
             hook = self.__class__.dispatch()
-        return hook(dispatcher=self, instance=instance, *args, **kwargs)
+        return hook(self, node, *args, **kwargs)
 
     @Hook(object)
-    def dispatch_object(self, instance, *args, **kwargs):
+    def dispatch_object(self, node, *args, **kwargs):
         raise NotImplementedError()
index ca6f80990f0e2362b5bce84bf8c69a98d79cd018..ff2617297877fb0fbfab4683e7f95339b8f38c96 100644 (file)
@@ -15,12 +15,12 @@ class VisitorMeta(dispatcher.DispatcherMeta):
 
 class Visitor(dispatcher.Dispatcher, metaclass=VisitorMeta):
     @dispatcher.Hook(object)
-    def dispatch_object(self, instance):
-        return instance
+    def dispatch_object(self, node):
+        return node
 
 
 class ContextVisitor(Visitor):
     @dispatcher.Hook(object)
     @contextlib.contextmanager
-    def dispatch_object(self, instance):
-        yield super().__call__(instance=instance)
+    def dispatch_object(self, node):
+        yield super().__call__(node)
index 55093556a1eacff5c18ebca0850cdcb94d0c4713..3605d0a5e9a861917d844e37cb003e5752484b5a 100644 (file)
@@ -46,33 +46,33 @@ class HashPath(GenericPath):
 
 class Walker(dispatcher.Dispatcher, metaclass=WalkerMeta):
     @dispatcher.Hook(tuple, list)
-    def dispatch_ordered_sequence(self, instance):
-        for (index, item) in enumerate(instance):
-            yield (item, instance, index, IndexPath)
+    def dispatch_ordered_sequence(self, node):
+        for (index, item) in enumerate(node):
+            yield (item, node, index, IndexPath)
             yield from self(item)
 
     @dispatcher.Hook(set, frozenset)
-    def dispatch_unordered_sequence(self, instance):
-        for item in instance:
-            yield (item, instance, item, HashPath)
+    def dispatch_unordered_sequence(self, node):
+        for item in node:
+            yield (item, node, item, HashPath)
             yield from self(item)
 
     @dispatcher.Hook(dataclasses.is_dataclass)
-    def dispatch_dataclass(self, instance):
-        for field in dataclasses.fields(instance):
+    def dispatch_dataclass(self, node):
+        for field in dataclasses.fields(node):
             key = field.name
-            value = getattr(instance, key)
-            yield (value, instance, key, AttributePath)
+            value = getattr(node, key)
+            yield (value, node, key, AttributePath)
             yield from self(value)
 
     @dispatcher.Hook(dict)
-    def dispatch_mapping(self, instance):
-        for (key, value) in instance.items():
-            yield (key, instance, key, HashPath)
+    def dispatch_mapping(self, node):
+        for (key, value) in node.items():
+            yield (key, node, key, HashPath)
             yield from self(key)
-            yield (value, instance, key, IndexPath)
+            yield (value, node, key, IndexPath)
             yield from self(value)
 
     @dispatcher.Hook(object)
-    def dispatch_object(self, instance, path=()):
+    def dispatch_object(self, node, path=()):
         yield from ()