curry.utility.visitation module
Implementation of the visitor pattern.
- class curry.utility.visitation.Visitable(selector, default)[source]
Bases:
objectImplements the “accept” half of a visitor pattern.
- property ordering
The ordering sorts classes by their (possibly abstract) subclass relationships. This is used when no handler provides an exact match. Computing the ordering is O(n^2) w.r.t. the number of handlers.
- class curry.utility.visitation.dispatch[source]
Bases:
objectCreates a new visitable function.
selectornames the function parameter used for dispatch.
- curry.utility.visitation.instance_checker(yes=None, no=None)[source]
Builds a this-but-not-that instance checker class.
The class returned is intended to be used with
isinstanceandissubclass. An object will be an instance of the returned class if it is an instance ofyesbut not an instance ofno. Likewise for subclasses. Either argument may be a tuple of classes.Identical calls to this function are guaranteed to return the same object, so the result may be used as a key.