'Returns the best signature out of the candidates'

def _best_signature(self, candidates):

    (ordered, genericity) = self._sort_signatures(candidates)
    if (len(ordered) > 1):
        firstscore = genericity[ordered[0]]
        same = list(takewhile((lambda x: (genericity[x] == firstscore)), ordered))
        if (len(same) > 1):
            msg = ['{n}    ambiguous    signatures'.format(n=len(same))]
            for sig in same:
                msg += ['{0}    =>    {1}'.format(sig, candidates[sig])]
            raise TypeError('\n'.join(msg))
    return ordered[0]
