[Libre-soc-bugs] [Bug 1094] insndb instruction database visitor-walker is needed

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Tue Jun 20 22:34:03 BST 2023


https://bugs.libre-soc.org/show_bug.cgi?id=1094

--- Comment #218 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
am on atrain. late. brief.

(In reply to Dmitry Selyutin from comment #208)
> OK, I found a way to handle paths elegantly and keep the original
> identifiers as well. The trick is to yield both the original
> key/index/element and something which designates how to format it.

ahh i love that idea, just be careful the "formatter" does not
expand out to "and we need another feature, and another".

> https://git.libre-soc.org/?p=mdis.git;a=commitdiff;
> h=c025a35e2d0f1fc3701d266aea52a0cb00abd8b7

     @dispatcher.Hook(dataclasses.is_dataclass)
-    def dispatch_dataclass(self, instance):
+    def dispatch_dataclass(self, instance, path=[]):  <- path=()
         for field in dataclasses.fields(instance):
             key = field.name
             value = getattr(instance, key)
-            yield (key, value)
-            yield from self((key, value))
+            part = (PartId.Attribute, key)
+            parts = (path + (part,))
+            yield (value, parts)
+            yield from self(value, path=parts)
+
+    @dispatcher.Hook(dict)
+    def dispatch_mapping(self, instance, path=[]): <- path=()
+        for (key, value) in instance.items():

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list