def look_for_nearby_compatible_socket(self, mouse_pos):
        """Reference nearby compatible socket, if any."""
        ### reference magnet point locally and set it to the mouse position

        mp = self.magnet_point
        mp.update(mouse_pos)

        ### reference socket detection values locally for easier/quicker
        ### access

        detection_distance = USER_PREFS['DETECTION_DISTANCE']
        grasping_distance = USER_PREFS['GRASPING_DISTANCE']

        ### define how much to inflate a node to obtain an area used to
        ### detect whether the mouse is close enough to a node
        node_inflation = detection_distance * 2

        ### assume there's no compatible socket nearby
        self.socket_b = self.socket_b_candidate = None

        ### grab reference to our node
        our_node = self.socket_a.node

        ### grab compatible socket from nearby nodes (if any)

        retrieve_sockets = self.get_compatible_sockets

        sockets = chain.from_iterable(

            retrieve_sockets(node)
            for node in self.nodes.get_on_screen()

            if (

                (
                    node.rect
                    .inflate(node_inflation, node_inflation)
                    .collidepoint(mouse_pos)
                )

                and node is not our_node

            )

        )

        ### try grabing the closest socket

        key_func = lambda item: mp.distance_to(item.rect.center)

        try:
            closest_socket = min(sockets, key=key_func)

        ### if none is found, just pass

        except ValueError:
            pass

        ### if one is found though, store a reference to it
        ### and other values depending on how close it is

        else:

            distance = mp.distance_to(closest_socket.rect.center)

            if distance < grasping_distance:
                self.socket_b = closest_socket

            elif distance < detection_distance:

                self.socket_b_candidate = closest_socket

                # offset_grasping_distance 
                og_distance = grasping_distance - 5

                # difference_between_distances 
                difference = detection_distance - og_distance

                # store percentage of difference from socket candidate
                # to mouse

                self.percentage_to_mouse = (
                    1 - ((distance - og_distance) / difference)
                )
Reference nearby compatible socket, if any.
nodezator/graphman/socketparenthood/action.py