Visitor pattern #22
Replies: 3 comments
-
Hey @tristanlatr , could you elaborate on what makes the existing |
Beta Was this translation helpful? Give feedback.
-
Hi, It’s not insufficient in itself. I could probably hack something that would work with that function. But the visitor pattern makes the visitor logic much more clear. And it ressembles common visitor present in other packages like ast or docutils. Tell me what you think. |
Beta Was this translation helpful? Give feedback.
-
I will submit a PR with the following generic visitor: https://github.com/twisted/pydoctor/blob/json-docspec/pydoctor/visitor.py It's "installed" on the ApiObject class with the following code: def _get_children(self) -> t.Iterable['ApiObject']:
if isinstance(self, HasMembers):
return self.members
else:
return ()
def walk(self, v: visitor.Visitor['ApiObject']) -> None:
visitor.walk(self, v, get_children=self._get_children)
def walkabout(self, v: visitor.Visitor['ApiObject']) -> None:
visitor.walkabout(self, v, get_children=self._get_children) It also ships with See my code here: https://github.com/twisted/pydoctor/tree/json-docspec/pydoctor/docspec Note that I've remove all the stuff that was unnecessary for me, but I won't do that with this repo. I'll continue to submit patches such that the required modifications that i've done in the fork are also present in this repository, then I'll make Tell me what you think, Thanks. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm working on a modified version of
docspec
and I've implemented the actual visitor pattern.The pattern is composed by a super class:
ApiObjectVisitor
and the addition of 2 methods to the ApiObject class:walk(self, visitor: 'ApiObjectVisitor')
andwalkabout(self, visitor: 'ApiObjectVisitor')
. The design is inspired from docutils NodeVisitor.I could port those object to this version as well.
Tell me if you are interested.
Beta Was this translation helpful? Give feedback.
All reactions