Skip to content

Latest commit

 

History

History
67 lines (46 loc) · 1.7 KB

usage.rst

File metadata and controls

67 lines (46 loc) · 1.7 KB

Usage

doorbell

The Visitee

provides Visitee, an abstract base class with a single method, Visitee.accept. Implementations of Visitee.accept typically only consist of a single line:

def accept(self, visitor):
   return visitor.visit_MyType(self)

where visit_MyType is the method on the visitor which applies to this particular object. Typically, only the object (self) is passed, although any arguments will be passed along to the visitor's method.

Several decoratormethod are provided to aid in creating the accept method:

~Visitee.create ~Visitee.auto_create ~Visitee.stop_auto_create

The Visitor

The base Visitor class and its children are the main products of . Your visitor class inherits from Visitor or its children, and implements a set of methods which are called from a Visitee.accpet. By default, any method whose name begins visit_ is considered a visitor method. However, the decorators:

~Visitor.visitor_method ~Visitor.non_visitor_method

override this default. Any method decorated with ~Visitor.visitor_method will be considered a visitor method, while any method decorated with ~Visitor.non_visitor_method will not be considered a visitor method. All visitor methods are wrapped by Visitor._visit_method.

The following visitor classes are provided:

~Visitor ~CascadingVisitor ~WrappingVisitor