# Buggy code
def unexpected_keyword_argument(
    self, callee: CallableType, name: str, context: Context
) -> None:
    msg = 'Unexpected keyword argument "{}"'.format(name)
    if callee.name:
        msg += " for {}".format(callee.name)
    self.fail(msg, context)
    if callee.definition:
        fullname = callee.definition.fullname()
        if fullname is not None and "." in fullname:
            module_name = fullname.rsplit(".", 1)[0]
            path = self.modules[module_name].path
            self.note(
                "{} defined here".format(callee.name),
                callee.definition,
                file=path,
                origin=context,
            )


# Traceback (KeyError)
(e2e) Adam@Adams-MacBook-Pro ~/Desktop> mypy example.py --show-traceback
example.py:2: error: Unexpected keyword argument "example" for "Popen"
example.py:2: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.511
Traceback (most recent call last):
File "/Users/Adam/.virtualenvs/e2e/bin/mypy", line 6, in <module>
main(__file__)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/main.py", line 46, in main
res = type_check_only(sources, bin_dir, options)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/main.py", line 93, in type_check_only
options=options)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 188, in build
graph = dispatch(sources, manager)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 1595, in dispatch
process_graph(graph, manager)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 1838, in process_graph
process_stale_scc(graph, scc, manager)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 1937, in process_stale_scc
graph[id].type_check_first_pass()
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 1510, in type_check_first_pass
self.type_checker.check_first_pass()
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checker.py", line 177, in check_first_pass
self.accept(d)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checker.py", line 264, in accept
stmt.accept(self)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/nodes.py", line 825, in accept
return visitor.visit_expression_stmt(self)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checker.py", line 1823, in visit_expression_stmt
self.expr_checker.accept(s.expr, allow_none_return=True)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 2054, in accept
typ = self.visit_call_expr(node, allow_none_return=True)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 201, in visit_call_expr
ret_type = self.check_call_expr_with_callee_type(callee_type, e)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 341, in check_call_expr_with_callee_type
e.arg_names, callable_node=e.callee)[0]
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 396, in check_call
arg_names, formal_to_actual, context, self.msg)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 759, in check_argument_count
callee, actual_names[i], context)
File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/messages.py", line 619, in unexpected_keyword_argument
path = self.modules[module_name].path
KeyError: 'subprocess.Popen'
example.py:2: note: use --pdb to drop into pdb

# Fixed code
def unexpected_keyword_argument(
    self, callee: CallableType, name: str, context: Context
) -> None:
    msg = 'Unexpected keyword argument "{}"'.format(name)
    if callee.name:
        msg += " for {}".format(callee.name)
    self.fail(msg, context)
    module = find_defining_module(self.modules, callee)
    if module:
        self.note(
            "{} defined here".format(callee.name),
            callee.definition,
            file=module.path,
            origin=context,
        )