def establish_segment(self, socket_a, socket_b):
        """Perform setups to establish new line segment."""
        ### perform extra setups depending on whether or not
        ### socket_a has children

        ## check whether socket_a has children
        try:
            children = socket_a.children

        ## setups in case the socket_a has no children

        except AttributeError:

            # add it to self.parents
            self.parents.append(socket_a)

            # create and append a new tree data entry for
            # the socket_a in the socket trees

            parent_data = {
                "id": socket_a.get_id(),
                "class_name": socket_a.__class__.__name__,
                "children": [],
            }

            self.parent_sockets_data.append(parent_data)

            # also reference the list in the 'children'
            # field of the tree data
            children_data = parent_data["children"]

            # create a new 'children' attribute containing
            # a list
            children = socket_a.children = []

        ## setups in case the socket_a already has children

        else:

            ## reference the 'children' field of the
            ## tree data for the socket_a

            socket_a_id = socket_a.get_id()

            for parent_data in self.parent_sockets_data:

                if parent_data["id"] == socket_a_id:
                    break

            children_data = parent_data["children"]

        ### append the socket_b as a child of socket_a and
        ### reference socket_a as its parent in its 'parent'
        ### attribute

        children.append(socket_b)
        socket_b.parent = socket_a

        ### check whether socket_b has a
        ### 'signal_connection' method
        try:
            signal_connection = socket_b.signal_connection

        ### if it doesn't have one, just pass
        except AttributeError:
            pass

        ### if it has, though, use the retrieved method to
        ### perform extra setups needed
        else:
            signal_connection()

        ### create and append the tree data for the socket_b
        ### in the children data of the socket_a

        child_data = {
            "id": socket_b.get_id(),
            "class_name": socket_b.__class__.__name__,
        }

        children_data.append(child_data)

        ### finally, if any of the nodes (the node of the
        ### socket_a or the node of the socket_b) is
        ### commented out, comment out the whole subgraph
        ### (the nodes which aren't already commented out)

        if any(
            socket.node.data.get("commented_out", False)
            for socket in (socket_a, socket_b)
        ):

            ## create a generator expression which yields
            ## uncommented nodes

            uncommented_nodes = (
                node
                for node in yield_subgraph_nodes(socket_a.node)
                if not node.data.get("commented_out", False)
            )

            ## iterate over such uncommented nodes,
            ## commenting them out

            for node in uncommented_nodes:

                node.data["commented_out"] = True
                node.perform_commenting_uncommenting_setups()
Perform setups to establish new line segment.
nodezator/graphman/socketparenthood/support.py