# Buggy code
def visit_tuple_type(self, left: TupleType) -> bool:
    right = self.right
    if isinstance(right, Instance):
        if is_named_instance(right, "typing.Sized"):
            return True
        elif (
            is_named_instance(right, "builtins.tuple")
            or is_named_instance(right, "typing.Iterable")
            or is_named_instance(right, "typing.Container")
            or is_named_instance(right, "typing.Sequence")
            or is_named_instance(right, "typing.Reversible")
        ):
            iter_type = right.args[0]
            return all(is_subtype(li, iter_type) for li in left.items)
        elif is_subtype(left.fallback, right, self.check_type_parameter):
            return True
        return False
    elif isinstance(right, TupleType):
        if len(left.items) != len(right.items):
            return False
        for l, r in zip(left.items, right.items):
            if not is_subtype(l, r, self.check_type_parameter):
                return False
        if not is_subtype(left.fallback, right.fallback, self.check_type_parameter):
            return False
        return True
    else:
        return False


# Traceback (IndexError)
$ mypy --show-traceback repro.py
repro.py:11: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues
Traceback (most recent call last):
File "/home/adrake/ve/app/bin/mypy", line 6, in <module>
main(__file__)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/main.py", line 41, in main
res = type_check_only(sources, bin_dir, options)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/main.py", line 86, in type_check_only
options=options)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/build.py", line 183, in build
dispatch(sources, manager)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/build.py", line 1512, in dispatch
process_graph(graph, manager)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/build.py", line 1692, in process_graph
process_stale_scc(graph, scc)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/build.py", line 1771, in process_stale_scc
graph[id].type_check_first_pass()
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/build.py", line 1440, in type_check_first_pass
self.type_checker.check_first_pass()
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 174, in check_first_pass
self.accept(d)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 243, in accept
typ = node.accept(self)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/nodes.py", line 532, in accept
return visitor.visit_func_def(self)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 455, in visit_func_def
self.check_func_item(defn, name=defn.name())
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 518, in check_func_item
self.check_func_def(defn, typ, name)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 648, in check_func_def
self.accept(item.body)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 243, in accept
typ = node.accept(self)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/nodes.py", line 771, in accept
return visitor.visit_block(self)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 1087, in visit_block
self.accept(s)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 243, in accept
typ = node.accept(self)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/nodes.py", line 785, in accept
return visitor.visit_expression_stmt(self)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 1522, in visit_expression_stmt
self.accept(s.expr)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 243, in accept
typ = node.accept(self)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/nodes.py", line 1247, in accept
return visitor.visit_call_expr(self)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 1968, in visit_call_expr
return self.expr_checker.visit_call_expr(e)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checkexpr.py", line 179, in visit_call_expr
return self.check_call_expr_with_callee_type(callee_type, e)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checkexpr.py", line 239, in check_call_expr_with_callee_type
e.arg_names, callable_node=e.callee)[0]
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checkexpr.py", line 280, in check_call
callee, args, arg_kinds, formal_to_actual, context)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checkexpr.py", line 539, in infer_function_type_arguments
context)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checkexpr.py", line 612, in apply_inferred_arguments
return self.apply_generic_arguments(callee_type, inferred_args, context)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checkexpr.py", line 884, in apply_generic_arguments
return applytype.apply_generic_arguments(callable, types, self.msg, context)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/applytype.py", line 37, in apply_generic_arguments
if mypy.subtypes.is_subtype(type, value):
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/subtypes.py", line 51, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/types.py", line 785, in accept
return visitor.visit_tuple_type(self)
File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/subtypes.py", line 174, in visit_tuple_type
iter_type = right.args[0]
IndexError: list index out of range

# Fixed code
def visit_tuple_type(self, left: TupleType) -> bool:
    right = self.right
    if isinstance(right, Instance):
        if is_named_instance(right, "typing.Sized"):
            return True
        elif (
            is_named_instance(right, "builtins.tuple")
            or is_named_instance(right, "typing.Iterable")
            or is_named_instance(right, "typing.Container")
            or is_named_instance(right, "typing.Sequence")
            or is_named_instance(right, "typing.Reversible")
        ):
            if right.args:
                iter_type = right.args[0]
            else:
                iter_type = AnyType()
            return all(is_subtype(li, iter_type) for li in left.items)
        elif is_subtype(left.fallback, right, self.check_type_parameter):
            return True
        return False
    elif isinstance(right, TupleType):
        if len(left.items) != len(right.items):
            return False
        for l, r in zip(left.items, right.items):
            if not is_subtype(l, r, self.check_type_parameter):
                return False
        if not is_subtype(left.fallback, right.fallback, self.check_type_parameter):
            return False
        return True
    else:
        return False