[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 19:51:02 BST 2023


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

--- Comment #209 from Dmitry Selyutin <ghostmansd at gmail.com> ---
Folks, based on the example below (A is a dataclass, cut for brevity):

items = (
    {("a", 1): 3.4, 2: {5, 6}},
    {3: A(5, [12, 3])},
)
for (item, path) in walker(items):
    with visitor(item, path=path):
        pass


Here are results:

     [0] => {('a', 1): 3.4, 2: {5, 6}}
         [0]{('a', 1)} => ('a', 1)
             [0]{('a', 1)}[0] => a
             [0]{('a', 1)}[1] => 1
         [0][('a', 1)] => 3.4
         [0]{2} => 2
         [0][2] => {5, 6}
             [0][2]{5} => 5
             [0][2]{6} => 6
     [1] => {3: A(a=5, b=[12, 3])}
         [1]{3} => 3
         [1][3] => A(a=5, b=[12, 3])
             [1][3].a => 5
             [1][3].b => [12, 3]
                 [1][3].b[0] => 12
                 [1][3].b[1] => 3


Does it meet your expectations? As you see I chose {} for hashes and pass the
stuff which was used. Currently these things cannot be accessed directly. I
think PartId, if used modified to be used with the parent, can not only format,
but also access parent in a correct way (via some lambda or whatever). Do we
need such functionality?
Perhaps we might yield something which is correctly formatted and on its
__call__ one can access the entity. Thoughts and opinion? I think it's somewhat
counter-intuitive, as we discussed, I'd like to keep the original value.
However, perhaps that's fine too?

for item in walker(items):
    print(item.path)
    print(item.parent)
    with visitor(item.node, path=path):
        pass

...instead of this:

for (node, parent, path) in walker(items):
    print(path)
    print(parent)
    with visitor(node, path=path):
        pass

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


More information about the libre-soc-bugs mailing list