def infer_annotation(type_comments):
    # type: (List[str]) -> Tuple[List[Argument], AbstractType]
    """Given some type comments, return a single inferred signature.

    Args:
        type_comments: Strings of form '(arg1, ... argN) -> ret'

    Returns: Tuple of (argument types and kinds, return type).
    """
    assert type_comments
    args = {}  # type: Dict[int, Set[Argument]]
    returns = set()
    for comment in type_comments:
        arg_types, return_type = parse_type_comment(comment)
        for i, arg_type in enumerate(arg_types):
            args.setdefault(i, set()).add(arg_type)
        returns.add(return_type)
    combined_args = []
    for i in sorted(args):
        arg_infos = list(args[i])
        kind = argument_kind(arg_infos)
        if kind is None:
            raise InferError('Ambiguous argument kinds:\n' + '\n'.join(type_comments))
        types = [arg.type for arg in arg_infos]
        combined = combine_types(types)
        if str(combined) == 'None':
            # It's very rare for an argument to actually be typed `None`, more likely than
            # not we simply don't have any data points for this argument.
            combined = UnionType([ClassType('None'), AnyType()])
        if kind != ARG_POS and (len(str(combined)) > 120 or isinstance(combined, UnionType)):
            # Avoid some noise.
            combined = AnyType()
        combined_args.append(Argument(combined, kind))
    combined_return = combine_types(returns)
    return combined_args, combined_return
def infer_annotation ( type_comments ) : assert type_comments args = { } returns = set ( ) for comment in type_comments : arg_types , return_type = parse_type_comment ( comment ) for i , arg_type in enumerate ( arg_types ) : args . setdefault ( i , set ( ) ) . add ( arg_type ) returns . add ( return_type ) combined_args = [ ] for i in sorted ( args ) : arg_infos = list ( args [ i ] ) kind = argument_kind ( arg_infos ) if kind is None : raise InferError ( 'Ambiguous argument kinds:\n' + '\n' . join ( type_comments ) ) types = [ arg . type for arg in arg_infos ] combined = combine_types ( types ) if str ( combined ) == 'None' : combined = UnionType ( [ ClassType ( 'None' ) , AnyType ( ) ] ) if kind != ARG_POS and ( len ( str ( combined ) ) > 120 or isinstance ( combined , UnionType ) ) : combined = AnyType ( ) combined_args . append ( Argument ( combined , kind ) ) combined_return = combine_types ( returns ) return combined_args , combined_return
Given some type comments, return a single inferred signature.

    Args:
        type_comments: Strings of form '(arg1, ... argN) -> ret'

    Returns: Tuple of (argument types and kinds, return type).