'Decorators are applied directly in DefNode and PyClassDefNode to avoid
reassignments to the function/class name - except for cdef class methods.
For those, the reassignment is required as methods are originally
defined in the PyMethodDef struct.
The IndirectionNode allows DefNode to override the decorator.'

@staticmethod
def chain_decorators(node, decorators, name):

    decorator_result = ExprNodes.NameNode(node.pos, name=name)
    for decorator in decorators[::(-1)]:
        decorator_result = ExprNodes.SimpleCallNode(decorator.pos, function=decorator.decorator, args=[decorator_result])
    name_node = ExprNodes.NameNode(node.pos, name=name)
    reassignment = Nodes.SingleAssignmentNode(node.pos, lhs=name_node, rhs=decorator_result)
    reassignment = Nodes.IndirectionNode([reassignment])
    node.decorator_indirection = reassignment
    return [node, reassignment]
