# Buggy code
def visit_instance(self, t: Instance) -> None:
    info = t.type
    if info.replaced or info.tuple_type:
        self.indicator["synthetic"] = True
    # Check type argument count.
    if len(t.args) != len(info.type_vars):
        if len(t.args) == 0:
            any_type = AnyType(
                TypeOfAny.from_omitted_generics, line=t.line, column=t.column
            )
            t.args = [any_type] * len(info.type_vars)
            return
        # Invalid number of type parameters.
        n = len(info.type_vars)
        s = "{} type arguments".format(n)
        if n == 0:
            s = "no type arguments"
        elif n == 1:
            s = "1 type argument"
        act = str(len(t.args))
        if act == "0":
            act = "none"
        self.fail('"{}" expects {}, but {} given'.format(info.name(), s, act), t)
        # Construct the correct number of type arguments, as
        # otherwise the type checker may crash as it expects
        # things to be right.
        t.args = [AnyType(TypeOfAny.from_error) for _ in info.type_vars]
        t.invalid = True
    elif info.defn.type_vars:
        # Check type argument values. This is postponed to the end of semantic analysis
        # since we need full MROs and resolved forward references.
        for tvar in info.defn.type_vars:
            if (
                tvar.values
                or not isinstance(tvar.upper_bound, Instance)
                or tvar.upper_bound.type.fullname() != "builtins.object"
            ):
                # Some restrictions on type variable. These can only be checked later
                # after we have final MROs and forward references have been resolved.
                self.indicator["typevar"] = True
    for arg in t.args:
        arg.accept(self)
    if info.is_newtype:
        for base in info.bases:
            base.accept(self)


# Traceback (IndexError)
.\break_mypy.py:22: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.560
Traceback (most recent call last):
File "c:\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Anaconda3\Scripts\mypy.exe\__main__.py", line 9, in <module>
sys.exit(console_entry())
File "c:\anaconda3\lib\site-packages\mypy\__main__.py", line 7, in console_entry
main(None)
File "c:\anaconda3\lib\site-packages\mypy\main.py", line 66, in main
res = type_check_only(sources, bin_dir, options)
File "c:\anaconda3\lib\site-packages\mypy\main.py", line 119, in type_check_only
options=options)
File "c:\anaconda3\lib\site-packages\mypy\build.py", line 218, in build
graph = dispatch(sources, manager)
File "c:\anaconda3\lib\site-packages\mypy\build.py", line 1997, in dispatch
process_graph(graph, manager)
File "c:\anaconda3\lib\site-packages\mypy\build.py", line 2299, in process_graph
process_stale_scc(graph, scc, manager)
File "c:\anaconda3\lib\site-packages\mypy\build.py", line 2475, in process_stale_scc
graph[id].type_check_first_pass()
File "c:\anaconda3\lib\site-packages\mypy\build.py", line 1876, in type_check_first_pass
self.type_checker().check_first_pass()
File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 196, in check_first_pass
self.accept(d)
File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 286, in accept
stmt.accept(self)
File "c:\anaconda3\lib\site-packages\mypy\nodes.py", line 497, in accept
return visitor.visit_func_def(self)
File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 534, in visit_func_def
self.check_func_item(defn, name=defn.name())
File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 599, in check_func_item
self.check_func_def(defn, typ, name)
File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 762, in check_func_def
self.accept(item.body)
File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 286, in accept
stmt.accept(self)
File "c:\anaconda3\lib\site-packages\mypy\nodes.py", line 756, in accept
return visitor.visit_block(self)
File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 1330, in visit_block
self.accept(s)
File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 286, in accept
stmt.accept(self)
File "c:\anaconda3\lib\site-packages\mypy\nodes.py", line 770, in accept
return visitor.visit_expression_stmt(self)
File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 2097, in visit_expression_stmt
self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)
File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 2361, in accept
typ = self.visit_call_expr(node, allow_none_return=True)
File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 268, in visit_call_expr
ret_type = self.check_call_expr_with_callee_type(callee_type, e, fullname, object_type)
File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 505, in check_call_expr_with_callee_type
object_type=object_type)[0]
File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 611, in check_call
object_type=object_type)
File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 568, in check_call
callee, args, arg_kinds, formal_to_actual, context)
File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 823, in infer_function_type_arguments
inferred_args, context)
File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 877, in infer_function_type_arguments_pass2
callee_type, arg_types, arg_kinds, formal_to_actual)
File "c:\anaconda3\lib\site-packages\mypy\infer.py", line 31, in infer_function_type_arguments
callee_type, arg_types, arg_kinds, formal_to_actual)
File "c:\anaconda3\lib\site-packages\mypy\constraints.py", line 63, in infer_constraints_for_callable
SUPERTYPE_OF)
File "c:\anaconda3\lib\site-packages\mypy\constraints.py", line 174, in infer_constraints
return template.accept(ConstraintBuilderVisitor(actual, direction))
File "c:\anaconda3\lib\site-packages\mypy\types.py", line 739, in accept
return visitor.visit_callable_type(self)
File "c:\anaconda3\lib\site-packages\mypy\constraints.py", line 415, in visit_callable_type
res.extend(infer_constraints(t, a, neg_op(self.direction)))
File "c:\anaconda3\lib\site-packages\mypy\constraints.py", line 174, in infer_constraints
return template.accept(ConstraintBuilderVisitor(actual, direction))
File "c:\anaconda3\lib\site-packages\mypy\types.py", line 475, in accept
return visitor.visit_instance(self)
File "c:\anaconda3\lib\site-packages\mypy\constraints.py", line 326, in visit_instance
mapped.args[i], instance.args[i], self.direction))
IndexError: list index out of range
.\break_mypy.py:22: : note: use --pdb to drop into pdb

# Fixed code
def visit_instance(self, t: Instance) -> None:
    info = t.type
    if info.replaced or info.tuple_type:
        self.indicator["synthetic"] = True
    # Check type argument count.
    if len(t.args) != len(info.type_vars):
        fix_instance(t, self.fail)
    elif info.defn.type_vars:
        # Check type argument values. This is postponed to the end of semantic analysis
        # since we need full MROs and resolved forward references.
        for tvar in info.defn.type_vars:
            if (
                tvar.values
                or not isinstance(tvar.upper_bound, Instance)
                or tvar.upper_bound.type.fullname() != "builtins.object"
            ):
                # Some restrictions on type variable. These can only be checked later
                # after we have final MROs and forward references have been resolved.
                self.indicator["typevar"] = True
    for arg in t.args:
        arg.accept(self)
    if info.is_newtype:
        for base in info.bases:
            base.accept(self)