# Buggy code
def map_instance_to_supertypes(
    instance: Instance, supertype: TypeInfo
) -> List[Instance]:
    # FIX: Currently we should only have one supertype per interface, so no
    #      need to return an array
    result = []  # type: List[Instance]
    for path in class_derivation_paths(instance.type, supertype):
        types = [instance]
        for sup in path:
            a = []  # type: List[Instance]
            for t in types:
                a.extend(map_instance_to_direct_supertypes(t, sup))
            types = a
        result.extend(types)
    return result


# Traceback (IndexError)
t_test6.py:1: error: Invalid base class
t_test6.py:5: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues
Traceback (most recent call last):
File "/usr/local/bin/mypy", line 6, in <module>
main(__file__)
File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 38, in main
res = type_check_only(sources, bin_dir, options)
File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 79, in type_check_only
options=options)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 181, in build
dispatch(sources, manager)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1470, in dispatch
process_graph(graph, manager)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1650, in process_graph
process_stale_scc(graph, scc)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1729, in process_stale_scc
graph[id].type_check()
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1415, in type_check
manager.type_checker.visit_file(self.tree, self.xpath, self.options)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 165, in visit_file
self.accept(d)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 217, in accept
typ = node.accept(self)
File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 796, in accept
return visitor.visit_assignment_stmt(self)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1028, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1044, in check_assignment
infer_lvalue_type)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1129, in check_assignment_to_multiple_lvalues
self.check_multi_assignment(lvalues, rvalue, context, infer_lvalue_type)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1165, in check_multi_assignment
context, infer_lvalue_type)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1257, in check_multi_assignment_from_iterable
item_type = self.iterable_item_type(cast(Instance, rvalue_type))
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 2321, in iterable_item_type
self.lookup_typeinfo('typing.Iterable'))
File "/usr/local/lib/python3.4/dist-packages/mypy/maptype.py", line 23, in map_instance_to_supertype
return map_instance_to_supertypes(instance, superclass)[0]
IndexError: list index out of range
t_test6.py:5: note: use --pdb to drop into pdb

# Fixed code
def map_instance_to_supertypes(
    instance: Instance, supertype: TypeInfo
) -> List[Instance]:
    # FIX: Currently we should only have one supertype per interface, so no
    #      need to return an array
    result = []  # type: List[Instance]
    for path in class_derivation_paths(instance.type, supertype):
        types = [instance]
        for sup in path:
            a = []  # type: List[Instance]
            for t in types:
                a.extend(map_instance_to_direct_supertypes(t, sup))
            types = a
        result.extend(types)
    if result:
        return result
    else:
        # Nothing. Presumably due to an error. Construct a dummy using Any.
        return [Instance(supertype, [AnyType()] * len(supertype.type_vars))]