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

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Sun Jun 18 23:21:53 BST 2023


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

--- Comment #177 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
(In reply to Dmitry Selyutin from comment #166)


> dicts and dataclasses, on the other hand, yield key too. Should the
> dispatcher look like this instead?
> 
>     @dispatcher.Hook(tuple, list, set, frozenset)
>     def dispatch_sequence(self, instance):
>         for (index, item) in enumerate(instance):
>             yield (index, item)
>             yield from self(item)

like it.  corresponding dispatch.py change:

  84     def __call__(self, instance, *args):
  85         for typeid in instance.__class__.__mro__:
  86             hook = self.__class__.dispatch(typeid=typeid)
  87             if hook is not None:
  88                 break
  89         if hook is None:
  90             hook = self.__class__.dispatch()
  91         return hook(dispatcher=self, instance=instance, *args)

which will need this instead:

     @dispatcher.Hook(tuple, list, set, frozenset)
     def dispatch_sequence(self, instance):
         for (index, item) in enumerate(instance):
      -->    yield (item, index) <-- swapped: item first
             yield from self(item)


> Also, whilst we're at it, we could perhaps support namedtuple default hook

awesome!

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


More information about the libre-soc-bugs mailing list