[Libre-soc-bugs] [Bug 1094] insndb instruction database visitor-walker is needed
bugzilla-daemon at libre-soc.org
bugzilla-daemon at libre-soc.org
Sat Jun 10 09:21:59 BST 2023
https://bugs.libre-soc.org/show_bug.cgi?id=1094
--- Comment #82 from Dmitry Selyutin <ghostmansd at gmail.com> ---
Long story short. I share your opinion almost on everything, but I had to at
least probe this route to understand its pros and cons.
The only exception is generic __call__. This actually comes from your
isinstance hints (about another section?), but I realized that relying on class
name is too fragile. isinstance refers to an object (yes, types are objects too
in Python); name just refers to some string. Whilst it looks simpler, it's
indeed less intuitive than explicit checks. If somebody wants this
functionality (per-class context managers), they can do it directly in concrete
visitors:
class WeirdVisitor(Visitor):
@contextlib.contextmanager
def __call__(self, node):
method = getattr(self, node.__class__.__name__, self.Node)
return method(node)
@contextlib.contextmanager
def Node(self, node):
raise 666
@contextlib.contextmanager
def Record(self, node):
raise 42
TL;DR: I'm removing paths branch. However, there's still one issue with the
approach you suggest.
def __call__(self, node):
print("/".join(self.stack_of_stuff), node)
self.stack_of_stuff.append(node.name)
yield node
self.stack_of_stuff.pop(-1) # i think
I'f we're going to drop the Node-inherited classes (Path, String and similar
stuff), there's no way we could call node.name (or, again, some other generic
field, because "name" is occupied). `str` or `bool` don't have such interface.
As for bool inheritance, that's not a problem: whilst bool isn't inheritable,
int is.
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the libre-soc-bugs
mailing list