Commit 908ea437 authored by Kelvin Rodriguez's avatar Kelvin Rodriguez
Browse files

docs for decorator generator

parent baaa0722
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -55,8 +55,7 @@ class CandidateGraph(nx.Graph):
    edge_attr_dict_factory = Edge

    def __init__(self, *args, basepath=None, **kwargs):
        self.edge_attr_dict_factory = decorate_class(Edge, create_cg_updater(self), exclude=['clean', 'get_keypoints'])

        # self.edge_attr_dict_factory = decorate_class(Edge, create_cg_updater(self), exclude=['clean', 'get_keypoints'])
        super(CandidateGraph, self).__init__(*args, **kwargs)
        self.graph['node_counter'] = 0
        node_labels = {}
+5 −3
Original line number Diff line number Diff line
@@ -399,14 +399,16 @@ def decorate_class(cls, decorator, exclude=[], *args, **kwargs):
    # return decorated copy (i.e. a subclass with decorations)
    return decorate(type('cls_copy', cls.__bases__, dict(cls.__dict__)))

def create_cg_updater(cg):
def create_decorator(*args, **kwargs):
    """
    Create a decorator function using object
    Create a decorator function using arbirary params. The objects passed in
    can be used in the body. Originally designed with the idea of automatically
    updating one object after the decorated object was modified. 
    """
    def decorator(func):
        def wrapper(self, *args, **kwargs):
            ret = func(self, *args, **kwargs)
            # do something with cg
            # do something with obj
            if ret:
                return ret
        return wrapper