def set_override(self, ctx, override_node):
        """
        Sets an override node for this node in this context.
        
        Once an override is set this node delegates its evaluation
        to the override_node whenever its evaluated in ``ctx``.
        """
        shift_set = ctx.get_shift_set()
        if shift_set and override_node is not shift_set.get(self, None):
            raise Exception("Nodes can only be overriden in the root context, "
                            "or if the context is shifted by the node being overriden")       

        # get the root context the override is being applied to
        root_ctx = cython.declare(MDFContext)
        root_ctx = ctx.get_parent() or ctx
        if self in shift_set:
            # the the context only shifted by this node (ctx could be shifted by other nodes as well)
            root_ctx = root_ctx.shift({self : override_node})

        # early out if the context is already shifted by override_node
        node_state = cython.declare(NodeState)
        node_state = self._get_state(root_ctx)
        if node_state.override is override_node:
            return

        # set the override node to be used by get_value
        node_state.override = override_node

        # reset the state for the root context and all shifts of it
        all_contexts = set([root_ctx])
        if root_ctx.get_parent() is not None:
            all_contexts.update(root_ctx.get_parent().get_shifted_contexts())

        for ctx in all_contexts:
            if ctx is root_ctx \
            or ctx.is_shift_of(root_ctx):
                # let any dependencies know the value of this node is invalid
                self.set_dirty(ctx, DIRTY_FLAGS_ALL)

                # clear any cached dependencies as they've changed
                self._clear_dependency_cache(ctx)

                try:
                    node_state = self._states[ctx._id_obj]
                    node_state.alt_context = None
                    node_state.prev_alt_context = None
                    node_state.override_cache = None
                    node_state.callees.clear()
                    node_state.add_dependency_cache.clear()
                except __HOLE__:
                    pass
dataset/ETHPy150Open manahl/mdf/mdf/nodes.py/MDFNode.set_override