# Buggy code
def overload_call_target(
    self,
    arg_types: List[Type],
    arg_kinds: List[int],
    arg_names: List[str],
    overload: Overloaded,
    context: Context,
    messages: MessageBuilder = None,
) -> Type:
    """Infer the correct overload item to call with given argument types.

    The return value may be CallableType or AnyType (if an unique item
    could not be determined).
    """
    messages = messages or self.msg
    # TODO: For overlapping signatures we should try to get a more precise
    #       result than 'Any'.
    match = []  # type: List[CallableType]
    best_match = 0
    for typ in overload.items():
        similarity = self.erased_signature_similarity(
            arg_types, arg_kinds, arg_names, typ
        )
        if similarity > 0 and similarity >= best_match:
            if (
                match
                and not is_same_type(match[-1].ret_type, typ.ret_type)
                and not mypy.checker.is_more_precise_signature(match[-1], typ)
            ):
                # Ambiguous return type. Either the function overload is
                # overlapping (which we don't handle very well here) or the
                # caller has provided some Any argument types; in either
                # case we'll fall back to Any. It's okay to use Any types
                # in calls.
                #
                # Overlapping overload items are generally fine if the
                # overlapping is only possible when there is multiple
                # inheritance, as this is rare. See docstring of
                # mypy.meet.is_overlapping_types for more about this.
                #
                # Note that there is no ambiguity if the items are
                # covariant in both argument types and return types with
                # respect to type precision. We'll pick the best/closest
                # match.
                #
                # TODO: Consider returning a union type instead if the
                #       overlapping is NOT due to Any types?
                return AnyType()
            else:
                match.append(typ)
            best_match = max(best_match, similarity)
    if not match:
        messages.no_variant_matches_arguments(overload, arg_types, context)
        return AnyType()
    else:
        if len(match) == 1:
            return match[0]
        else:
            # More than one signature matches. Pick the first *non-erased*
            # matching signature, or default to the first one if none
            # match.
            for m in match:
                if self.match_signature_types(arg_types, arg_kinds, arg_names, m):
                    return m
            return match[0]


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/lib/python-exec/python3.4/mypy", line 6, in <module>
main(__file__)
File "/usr/lib64/python3.4/site-packages/mypy/main.py", line 54, in main
res = type_check_only(sources, bin_dir, options)
File "/usr/lib64/python3.4/site-packages/mypy/main.py", line 102, in type_check_only
python_path=options.python_path)
File "/usr/lib64/python3.4/site-packages/mypy/build.py", line 209, in build
dispatch(sources, manager)
File "/usr/lib64/python3.4/site-packages/mypy/build.py", line 1325, in dispatch
process_graph(graph, manager)
File "/usr/lib64/python3.4/site-packages/mypy/build.py", line 1456, in process_graph
process_stale_scc(graph, scc)
File "/usr/lib64/python3.4/site-packages/mypy/build.py", line 1486, in process_stale_scc
graph[id].type_check()
File "/usr/lib64/python3.4/site-packages/mypy/build.py", line 1305, in type_check
manager.type_checker.visit_file(self.tree, self.xpath)
File "/usr/lib64/python3.4/site-packages/mypy/checker.py", line 424, in visit_file
self.accept(d)
File "/usr/lib64/python3.4/site-packages/mypy/checker.py", line 465, in accept
typ = node.accept(self)
File "/usr/lib64/python3.4/site-packages/mypy/nodes.py", line 729, in accept
return visitor.visit_expression_stmt(self)
File "/usr/lib64/python3.4/site-packages/mypy/checker.py", line 1570, in visit_expression_stmt
self.accept(s.expr)
File "/usr/lib64/python3.4/site-packages/mypy/checker.py", line 465, in accept
typ = node.accept(self)
File "/usr/lib64/python3.4/site-packages/mypy/nodes.py", line 1185, in accept
return visitor.visit_call_expr(self)
File "/usr/lib64/python3.4/site-packages/mypy/checker.py", line 1997, in visit_call_expr
return self.expr_checker.visit_call_expr(e)
File "/usr/lib64/python3.4/site-packages/mypy/checkexpr.py", line 141, in visit_call_expr
return self.check_call_expr_with_callee_type(callee_type, e)
File "/usr/lib64/python3.4/site-packages/mypy/checkexpr.py", line 192, in check_call_expr_with_callee_type
e.arg_names, callable_node=e.callee)[0]
File "/usr/lib64/python3.4/site-packages/mypy/checkexpr.py", line 257, in check_call
messages=arg_messages)
File "/usr/lib64/python3.4/site-packages/mypy/checkexpr.py", line 666, in overload_call_target
typ)
File "/usr/lib64/python3.4/site-packages/mypy/checkexpr.py", line 742, in erased_signature_similarity
None, check_arg=check_arg)
File "/usr/lib64/python3.4/site-packages/mypy/checkexpr.py", line 614, in check_argument_types
messages.invalid_keyword_var_arg(arg_type, context)
File "/usr/lib64/python3.4/site-packages/mypy/messages.py", line 687, in invalid_keyword_var_arg
context)
File "/usr/lib64/python3.4/site-packages/mypy/messages.py", line 147, in fail
self.report(msg, context, 'error', file=file)
File "/usr/lib64/python3.4/site-packages/mypy/messages.py", line 143, in report
self.errors.report(context.get_line(), msg.strip(), severity=severity, file=file)
AttributeError: 'NoneType' object has no attribute 'get_line'

# Fixed code
def overload_call_target(
    self,
    arg_types: List[Type],
    arg_kinds: List[int],
    arg_names: List[str],
    overload: Overloaded,
    context: Context,
    messages: MessageBuilder = None,
) -> Type:
    """Infer the correct overload item to call with given argument types.

    The return value may be CallableType or AnyType (if an unique item
    could not be determined).
    """
    messages = messages or self.msg
    # TODO: For overlapping signatures we should try to get a more precise
    #       result than 'Any'.
    match = []  # type: List[CallableType]
    best_match = 0
    for typ in overload.items():
        similarity = self.erased_signature_similarity(
            arg_types, arg_kinds, arg_names, typ, context=context
        )
        if similarity > 0 and similarity >= best_match:
            if (
                match
                and not is_same_type(match[-1].ret_type, typ.ret_type)
                and not mypy.checker.is_more_precise_signature(match[-1], typ)
            ):
                # Ambiguous return type. Either the function overload is
                # overlapping (which we don't handle very well here) or the
                # caller has provided some Any argument types; in either
                # case we'll fall back to Any. It's okay to use Any types
                # in calls.
                #
                # Overlapping overload items are generally fine if the
                # overlapping is only possible when there is multiple
                # inheritance, as this is rare. See docstring of
                # mypy.meet.is_overlapping_types for more about this.
                #
                # Note that there is no ambiguity if the items are
                # covariant in both argument types and return types with
                # respect to type precision. We'll pick the best/closest
                # match.
                #
                # TODO: Consider returning a union type instead if the
                #       overlapping is NOT due to Any types?
                return AnyType()
            else:
                match.append(typ)
            best_match = max(best_match, similarity)
    if not match:
        messages.no_variant_matches_arguments(overload, arg_types, context)
        return AnyType()
    else:
        if len(match) == 1:
            return match[0]
        else:
            # More than one signature matches. Pick the first *non-erased*
            # matching signature, or default to the first one if none
            # match.
            for m in match:
                if self.match_signature_types(
                    arg_types, arg_kinds, arg_names, m, context=context
                ):
                    return m
            return match[0]