curry.utility.visitation module

Implementation of the visitor pattern.

class curry.utility.visitation.Visitable(selector, default)[source]

Bases: object

Implements 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.

when(ty, replacement, no)[source]
class curry.utility.visitation.dispatch[source]

Bases: object

Creates a new visitable function. selector names the function parameter used for dispatch.

static on(selector)[source]
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 isinstance and issubclass. An object will be an instance of the returned class if it is an instance of yes but not an instance of no. 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.

curry.utility.visitation.toposort(data)[source]