def resolve_type(arg):
    # type: (object) -> InternalType
    """
    Resolve object to one of our internal collection types or generic built-in type.

    Args:
        arg: object to resolve
    """
    arg_type = type(arg)
    if arg_type == list:
        assert isinstance(arg, list)  # this line helps mypy figure out types
        sample = arg[:min(4, len(arg))]
        tentative_type = TentativeType()
        for sample_item in sample:
            tentative_type.add(resolve_type(sample_item))
        return ListType(tentative_type)
    elif arg_type == set:
        assert isinstance(arg, set)  # this line helps mypy figure out types
        sample = []
        iterator = iter(arg)
        for i in range(0, min(4, len(arg))):
            sample.append(next(iterator))
        tentative_type = TentativeType()
        for sample_item in sample:
            tentative_type.add(resolve_type(sample_item))
        return SetType(tentative_type)
    elif arg_type == FakeIterator:
        assert isinstance(arg, FakeIterator)  # this line helps mypy figure out types
        sample = []
        iterator = iter(arg)
        for i in range(0, min(4, len(arg))):
            sample.append(next(iterator))
        tentative_type = TentativeType()
        for sample_item in sample:
            tentative_type.add(resolve_type(sample_item))
        return IteratorType(tentative_type)
    elif arg_type == tuple:
        assert isinstance(arg, tuple)  # this line helps mypy figure out types
        sample = list(arg[:min(10, len(arg))])
        return TupleType([resolve_type(sample_item) for sample_item in sample])
    elif arg_type == dict:
        assert isinstance(arg, dict)  # this line helps mypy figure out types
        key_tt = TentativeType()
        val_tt = TentativeType()
        for i, (k, v) in enumerate(iteritems(arg)):
            if i > 4:
                break
            key_tt.add(resolve_type(k))
            val_tt.add(resolve_type(v))
        return DictType(key_tt, val_tt)
    else:
        return type(arg)
def resolve_type ( arg ) : arg_type = type ( arg ) if arg_type == list : assert isinstance ( arg , list ) sample = arg [ : min ( 4 , len ( arg ) ) ] tentative_type = TentativeType ( ) for sample_item in sample : tentative_type . add ( resolve_type ( sample_item ) ) return ListType ( tentative_type ) elif arg_type == set : assert isinstance ( arg , set ) sample = [ ] iterator = iter ( arg ) for i in range ( 0 , min ( 4 , len ( arg ) ) ) : sample . append ( next ( iterator ) ) tentative_type = TentativeType ( ) for sample_item in sample : tentative_type . add ( resolve_type ( sample_item ) ) return SetType ( tentative_type ) elif arg_type == FakeIterator : assert isinstance ( arg , FakeIterator ) sample = [ ] iterator = iter ( arg ) for i in range ( 0 , min ( 4 , len ( arg ) ) ) : sample . append ( next ( iterator ) ) tentative_type = TentativeType ( ) for sample_item in sample : tentative_type . add ( resolve_type ( sample_item ) ) return IteratorType ( tentative_type ) elif arg_type == tuple : assert isinstance ( arg , tuple ) sample = list ( arg [ : min ( 10 , len ( arg ) ) ] ) return TupleType ( [ resolve_type ( sample_item ) for sample_item in sample ] ) elif arg_type == dict : assert isinstance ( arg , dict ) key_tt = TentativeType ( ) val_tt = TentativeType ( ) for i , ( k , v ) in enumerate ( iteritems ( arg ) ) : if i > 4 : break key_tt . add ( resolve_type ( k ) ) val_tt . add ( resolve_type ( v ) ) return DictType ( key_tt , val_tt ) else : return type ( arg )
Resolve object to one of our internal collection types or generic built-in type.

    Args:
        arg: object to resolve