[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 10:29:00 BST 2023
https://bugs.libre-soc.org/show_bug.cgi?id=1094
--- Comment #88 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
(In reply to Dmitry Selyutin from comment #86)
> I just realized. No need to inherit everything in code from Node, unless
> required. We can just yield a proxy object, which wraps the original one but
> is inherited from Node.
eeehmmm... ehmehmehm... i'd love to see that in action, i can sort-of
subconsciously / intuitively see it would work but i don't know how :)
(In reply to Dmitry Selyutin from comment #87)
> About methods named as classes. If can you propose something that relies on
> _objects_, not _names_, I'm fine with that.
think it through: if we publish this as a generic pypi package
(and assume that the users are intelligent), will they freak out
at needing to inherit everything from "class Node" in their
project?
(remember i am considering replacing nmigen's Visitor-pattern with
this code)
> If not -- that's a strong no. No
> this does not comply with principle of a least surprise, it breaks it, in
> fact, even more than isinstance. The method generation should at least be
> hidden and not be explicit. I'll think how to handle it, but this should not
> be based on names from caller's perspective.
yyeah, i think we start to see why pyomo has a list of "builtin types",
and also why they have "register this class type with the walker system"
functions:
https://github.com/Pyomo/pyomo/blob/main/pyomo/common/numeric_types.py#L70
native_types is used back in the visitor code (in their equivalent
of the tree-walk function) to decide what to yield to the Visitor:
https://github.com/Pyomo/pyomo/blob/main/pyomo/core/expr/visitor.py#L1013
elif type(child) in native_types:
return False, child
actually... "type(child) in native_types" might be the right thing to do, here,
class Dataclass(metaclass=DataclassMeta):
@walkmethod
def walk(clsself, match=None):
...
field = (field_type if isinstance(clsself, type) else field_value)
yield from filter(match, map(field, _dataclasses.fields(clsself)))
-->
field = (field_value if type(child) in native_types else
(field_type if isinstance(clsself, type) else
field_value))
yield from filter(match, map(field, _dataclasses.fields(clsself)))
would that work? i'm running on instinct here.
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the libre-soc-bugs
mailing list