# Buggy code
def check_argument_kinds(
    self, funckinds: List[int], sigkinds: List[int], line: int
) -> None:
    """Check that * and ** arguments are consistent.

    Arguments:
      funckinds: kinds of arguments in function definition
      sigkinds:  kinds of arguments in signature (after # type:)
    """
    for kind, token in [(nodes.ARG_STAR, "*"), (nodes.ARG_STAR2, "**")]:
        if (funckinds.count(kind) != sigkinds.count(kind)) or (
            kind in funckinds and sigkinds.index(kind) != funckinds.index(kind)
        ):
            self.fail(
                "Inconsistent use of '{}' in function signature".format(token), line
            )


# Traceback (IndexError)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/bin/mypy", line 6, in <module>
main(__file__)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/main.py", line 54, in main
type_check_only(sources, bin_dir, options)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/main.py", line 98, in type_check_only
python_path=options.python_path)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/build.py", line 208, in build
result = manager.process(initial_states)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/build.py", line 393, in process
next.process()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/build.py", line 893, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 405, in visit_file
self.accept(d)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 446, in accept
typ = node.accept(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/nodes.py", line 540, in accept
return visitor.visit_expression_stmt(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 1533, in visit_expression_stmt
self.accept(s.expr)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 446, in accept
typ = node.accept(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/nodes.py", line 965, in accept
return visitor.visit_call_expr(self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 1931, in visit_call_expr
return self.expr_checker.visit_call_expr(e)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checkexpr.py", line 142, in visit_call_expr
return self.check_call_expr_with_callee_type(callee_type, e)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checkexpr.py", line 193, in check_call_expr_with_callee_type
e.arg_names, callable_node=e.callee)[0]
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checkexpr.py", line 236, in check_call
callee, args, arg_kinds, formal_to_actual)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checkexpr.py", line 328, in infer_arg_types_in_context2
res[ai] = self.accept(args[ai], callee.arg_types[i])
IndexError: list index out of range

*** INTERNAL ERROR ***

# Fixed code
def check_argument_kinds(
    self, funckinds: List[int], sigkinds: List[int], line: int
) -> None:
    """Check that arguments are consistent.

    This verifies that they have the same number and the kinds correspond.

    Arguments:
      funckinds: kinds of arguments in function definition
      sigkinds:  kinds of arguments in signature (after # type:)
    """
    if len(funckinds) != len(sigkinds):
        if len(funckinds) > len(sigkinds):
            self.fail("Type signature has too few arguments", line)
        else:
            self.fail("Type signature has too many arguments", line)
        return
    for kind, token in [(nodes.ARG_STAR, "*"), (nodes.ARG_STAR2, "**")]:
        if (funckinds.count(kind) != sigkinds.count(kind)) or (
            kind in funckinds and sigkinds.index(kind) != funckinds.index(kind)
        ):
            self.fail(
                "Inconsistent use of '{}' in function signature".format(token), line
            )