import socket


def localhost_has_free_port(port: int) -> bool:
    """Checks if the port is free on localhost.

    Args:
        port (int): The port which will be checked.
    Returns:
        bool: True if port is free, else False.
    """
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    is_success = sock.connect_ex(("localhost", port))
    return True if is_success else False