def from_same_file(node1, node2):
    """Checks if the two given nodes are from the same file."""
    return (
        node1.location.file is not None and
        node2.location.file is not None and
        node1.location.file.name == node2.location.file.name
    )