[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 19:29:12 BST 2023


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

--- Comment #160 from Dmitry Selyutin <ghostmansd at gmail.com> ---
import dataclasses

import mdis.dispatcher
import mdis.walker

class CustomWalker(mdis.walker.Walker):
    @mdis.dispatcher.Hook(dataclasses.is_dataclass)
    def dispatch_dataclass(self, instance):
        for field in dataclasses.fields(instance):
            key = field.name
            value = getattr(instance, key)
            yield (key, value)
            yield from self((key, value))

@dataclasses.dataclass
class Thing:
    a: int
    b: str

walker = CustomWalker()
thing = Thing(a=1, b="cocojamboo")
for item in walker(thing):
    print(repr(item))

('a', 1)
'a'
1
('b', 'cocojamboo')
'b'
'cocojamboo'

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


More information about the libre-soc-bugs mailing list