Skip to content

Fix and simplify error de-duplication #19247

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 6 additions & 7 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from mypy.constraints import SUPERTYPE_OF
from mypy.erasetype import erase_type, erase_typevars, remove_instance_last_known_values
from mypy.errorcodes import TYPE_VAR, UNUSED_AWAITABLE, UNUSED_COROUTINE, ErrorCode
from mypy.errors import Errors, ErrorWatcher, LoopErrorWatcher, report_internal_error
from mypy.errors import ErrorInfo, Errors, ErrorWatcher, LoopErrorWatcher, report_internal_error
from mypy.expandtype import expand_type
from mypy.literals import Key, extract_var_from_literal_hash, literal, literal_hash
from mypy.maptype import map_instance_to_supertype
Expand Down Expand Up @@ -7207,7 +7207,7 @@ def check_subtype(
if extra_info:
msg = msg.with_additional_msg(" (" + ", ".join(extra_info) + ")")

self.fail(msg, context)
error = self.fail(msg, context)
for note in notes:
self.msg.note(note, context, code=msg.code)
if note_msg:
Expand All @@ -7218,7 +7218,7 @@ def check_subtype(
and supertype.type.is_protocol
and isinstance(subtype, (CallableType, Instance, TupleType, TypedDictType))
):
self.msg.report_protocol_problems(subtype, supertype, context, code=msg.code)
self.msg.report_protocol_problems(subtype, supertype, context, parent_error=error)
if isinstance(supertype, CallableType) and isinstance(subtype, Instance):
call = find_member("__call__", subtype, subtype, is_operator=True)
if call:
Expand Down Expand Up @@ -7547,12 +7547,11 @@ def temp_node(self, t: Type, context: Context | None = None) -> TempNode:

def fail(
self, msg: str | ErrorMessage, context: Context, *, code: ErrorCode | None = None
) -> None:
) -> ErrorInfo:
"""Produce an error message."""
if isinstance(msg, ErrorMessage):
self.msg.fail(msg.value, context, code=msg.code)
return
self.msg.fail(msg, context, code=code)
return self.msg.fail(msg.value, context, code=msg.code)
return self.msg.fail(msg, context, code=code)

def note(
self,
Expand Down
8 changes: 5 additions & 3 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2647,7 +2647,7 @@ def check_arg(
elif self.has_abstract_type_part(caller_type, callee_type):
self.msg.concrete_only_call(callee_type, context)
elif not is_subtype(caller_type, callee_type, options=self.chk.options):
code = self.msg.incompatible_argument(
error = self.msg.incompatible_argument(
n,
m,
callee,
Expand All @@ -2658,10 +2658,12 @@ def check_arg(
outer_context=outer_context,
)
self.msg.incompatible_argument_note(
original_caller_type, callee_type, context, code=code
original_caller_type, callee_type, context, parent_error=error
)
if not self.msg.prefer_simple_messages():
self.chk.check_possible_missing_await(caller_type, callee_type, context, code)
self.chk.check_possible_missing_await(
caller_type, callee_type, context, error.code
)

def check_overload_call(
self,
Expand Down
Loading