Skip to content

Commit 3533a49

Browse files
committed
Update error message for incompatible args
Updated the error message that is displayed when the argument types of a method in a subclass are incompatible with the arguments of the same method in the superclass.
1 parent ace94cb commit 3533a49

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

mypy/checker.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,8 +1531,16 @@ def erase_override(t: Type) -> Type:
15311531
for i in range(len(override.arg_types)):
15321532
if not is_subtype(original.arg_types[i],
15331533
erase_override(override.arg_types[i])):
1534+
arg_type_in_super = original.arg_types[i]
15341535
self.msg.argument_incompatible_with_supertype(
1535-
i + 1, name, type_name, name_in_super, supertype, node)
1536+
i + 1,
1537+
name,
1538+
type_name,
1539+
name_in_super,
1540+
arg_type_in_super,
1541+
supertype,
1542+
node
1543+
)
15361544
emitted_msg = True
15371545

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

mypy/messages.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,13 @@ def signature_incompatible_with_supertype(
797797

798798
def argument_incompatible_with_supertype(
799799
self, arg_num: int, name: str, type_name: Optional[str],
800-
name_in_supertype: str, supertype: str, context: Context) -> None:
800+
name_in_supertype: str, arg_type_in_supertype: Type, supertype: str,
801+
context: Context) -> None:
801802
target = self.override_target(name, name_in_supertype, supertype)
802-
self.fail('Argument {} of "{}" incompatible with {}'
803-
.format(arg_num, name, target), context)
803+
arg_type_in_supertype_f = self.format_bare(arg_type_in_supertype)
804+
self.fail('Argument {} of "{}" is incompatible with {}; '
805+
'supertype defines the argument type as "{}"'
806+
.format(arg_num, name, target, arg_type_in_supertype_f), context)
804807

805808
if name == "__eq__" and type_name:
806809
multiline_msg = self.comparison_method_example_msg(class_name=type_name)

0 commit comments

Comments
 (0)