Skip to content

Prevent a crash in MessageBuilder.report() when context is None. #1583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def overload_call_target(self, arg_types: List[Type], arg_kinds: List[int],
best_match = 0
for typ in overload.items():
similarity = self.erased_signature_similarity(arg_types, arg_kinds, arg_names,
typ)
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
Expand Down Expand Up @@ -702,12 +702,14 @@ def overload_call_target(self, arg_types: List[Type], arg_kinds: List[int],
# 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):
if self.match_signature_types(arg_types, arg_kinds, arg_names, m,
context=context):
return m
return match[0]

def erased_signature_similarity(self, arg_types: List[Type], arg_kinds: List[int],
arg_names: List[str], callee: CallableType) -> int:
arg_names: List[str], callee: CallableType,
context: Context) -> int:
"""Determine whether arguments could match the signature at runtime.

Return similarity level (0 = no match, 1 = can match, 2 = non-promotion match). See
Expand Down Expand Up @@ -739,14 +741,15 @@ def check_arg(caller_type: Type, original_caller_type: Type, caller_kind: int,

try:
self.check_argument_types(arg_types, arg_kinds, callee, formal_to_actual,
None, check_arg=check_arg)
context=context, check_arg=check_arg)
except Finished:
pass

return similarity

def match_signature_types(self, arg_types: List[Type], arg_kinds: List[int],
arg_names: List[str], callee: CallableType) -> bool:
arg_names: List[str], callee: CallableType,
context: Context) -> bool:
"""Determine whether arguments types match the signature.

Assume that argument counts are compatible.
Expand All @@ -768,7 +771,7 @@ def check_arg(caller_type: Type, original_caller_type: Type, caller_kind: int,
ok = False

self.check_argument_types(arg_types, arg_kinds, callee, formal_to_actual,
None, check_arg=check_arg)
context=context, check_arg=check_arg)
return ok

def apply_generic_arguments(self, callable: CallableType, types: List[Type],
Expand Down
3 changes: 2 additions & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def is_errors(self) -> bool:
def report(self, msg: str, context: Context, severity: str, file: str = None) -> None:
"""Report an error or note (unless disabled)."""
if self.disable_count <= 0:
self.errors.report(context.get_line(), msg.strip(), severity=severity, file=file)
self.errors.report(context.get_line() if context else -1,
msg.strip(), severity=severity, file=file)

def fail(self, msg: str, context: Context, file: str = None) -> None:
"""Report an error message (unless disabled)."""
Expand Down