Skip to content

Commit d247fde

Browse files
committed
Pass the type name to the messages method
Instead of inspecting the context, we directly pass the type name to the messages methods as argument.
1 parent 15f1d06 commit d247fde

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

mypy/checker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,8 +1483,9 @@ def erase_override(t: Type) -> Type:
14831483
for i in range(len(override.arg_types)):
14841484
if not is_subtype(original.arg_types[i],
14851485
erase_override(override.arg_types[i])):
1486+
type_name = override.definition.info.name()
14861487
self.msg.argument_incompatible_with_supertype(
1487-
i + 1, name, name_in_super, supertype, node)
1488+
i + 1, name, type_name, name_in_super, supertype, node)
14881489
emitted_msg = True
14891490

14901491
if not is_subtype(erase_override(override.ret_type),

mypy/messages.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,15 +863,14 @@ def signature_incompatible_with_supertype(
863863
name, target), context)
864864

865865
def argument_incompatible_with_supertype(
866-
self, arg_num: int, name: str, name_in_supertype: str,
867-
supertype: str, context: Context) -> None:
866+
self, arg_num: int, name: str, type_name: str,
867+
name_in_supertype: str, supertype: str, context: Context) -> None:
868868
target = self.override_target(name, name_in_supertype, supertype)
869869
self.fail('Argument {} of "{}" incompatible with {}'
870870
.format(arg_num, name, target), context)
871871

872872
if name == "__eq__":
873-
assert isinstance(context, FuncDef)
874-
multiline_msg = self.comparison_method_example_msg(class_name=context.info.name())
873+
multiline_msg = self.comparison_method_example_msg(class_name=type_name)
875874
self.note_multiline(multiline_msg, context)
876875

877876
def comparison_method_example_msg(self, class_name: str) -> str:

0 commit comments

Comments
 (0)