rainwoodman commented on a change in pull request #16351:
URL: https://github.com/apache/beam/pull/16351#discussion_r815364028
##########
File path: sdks/python/apache_beam/typehints/typehints.py
##########
@@ -175,6 +175,35 @@ def visit(self, visitor, visitor_arg):
visitor(t, visitor_arg)
+def visit_inner_types(type_constraint, visitor, visitor_arg):
+ """Visitor pattern to visit all inner types of a type constraint.
+
+ Args:
+ type_constraint: A type constraint or a type.
+ visitor: A callable invoked for all nodes in the type tree comprising a
+ composite type. The visitor will be called with the node visited and the
+ visitor argument specified here.
+ visitor_arg: Visitor callback second argument.
+
+ Note:
+ Raise and capture a StopIteration to terminate the visit, e.g.
+
+ ```
+ def visitor(type_constraint, visitor_arg):
+ if ...:
+ raise StopIteration
+
+ try:
+ visit_inner_types(type_constraint, visitor, visitor_arg)
+ except StopIteration:
+ pass
+ ```
+ """
+ if isinstance(type_constraint, TypeConstraint):
+ return type_constraint.visit(visitor, visitor_arg)
+ return visitor(type_constraint, visitor_arg)
Review comment:
Probably not, because type_constraint argument here doesn't have to be a
TypeConstraint object. We shall probably refactor the logic out of
TypeConstraint.visit -- but I am not so sure as I don't recall why we need to
be able to handle the non-TypeConstraint members in the composite tree any
more. Any probably cause for that?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]