def VisitFunction(self, f):
    'Shrink a function, by factorizing cartesian products of arguments.\n\n    Greedily groups signatures, looking at the arguments from left to right.\n    This algorithm is *not* optimal. But it does the right thing for the\n    typical cases.\n\n    Arguments:\n      f: An instance of pytd.Function. If this function has more\n          than one signature, we will try to combine some of these signatures by\n          introducing union types.\n\n    Returns:\n      A new, potentially optimized, instance of pytd.Function.\n\n    '
    max_argument_count = max((len(s.params) for s in f.signatures))
    signatures = f.signatures
    for i in six.moves.xrange(max_argument_count):
        new_sigs = []
        for (sig, types) in self._GroupByOmittedArg(signatures, i):
            if types:
                new_params = list(sig.params)
                new_params[i] = sig.params[i].Replace(type=pytd_utils.JoinTypes(types))
                sig = sig.Replace(params=tuple(new_params))
                new_sigs.append(sig)
            else:
                new_sigs.append(sig)
        signatures = new_sigs
    return f.Replace(signatures=tuple(signatures))
Shrink a function, by factorizing cartesian products of arguments.

Greedily groups signatures, looking at the arguments from left to right.
This algorithm is *not* optimal. But it does the right thing for the
typical cases.

Arguments:
  f: An instance of pytd.Function. If this function has more
      than one signature, we will try to combine some of these signatures by
      introducing union types.

Returns:
  A new, potentially optimized, instance of pytd.Function.
def VisitFunction(self, f):
    'Shrink a function, by factorizing cartesian products of arguments.\n\n    Greedily groups signatures, looking at the arguments from left to right.\n    This algorithm is *not* optimal. But it does the right thing for the\n    typical cases.\n\n    Arguments:\n      f: An instance of pytd.Function. If this function has more\n          than one signature, we will try to combine some of these signatures by\n          introducing union types.\n\n    Returns:\n      A new, potentially optimized, instance of pytd.Function.\n\n    '
    max_argument_count = max((len(s.params) for s in f.signatures))
    signatures = f.signatures
    for i in six.moves.xrange(max_argument_count):
        new_sigs = []
        for (sig, types) in self._GroupByOmittedArg(signatures, i):
            if types:
                new_params = list(sig.params)
                new_params[i] = sig.params[i].Replace(type=pytd_utils.JoinTypes(types))
                sig = sig.Replace(params=tuple(new_params))
                new_sigs.append(sig)
            else:
                new_sigs.append(sig)
        signatures = new_sigs
    return f.Replace(signatures=tuple(signatures))