Skip to content

Commit 1c3dac5

Browse files
committed
signature_incompatible_with_supertype: show non-callables
1 parent 905c2cb commit 1c3dac5

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@ def check_method_override_for_base_with_name(
19881988
# If the attribute is read-only, allow covariance
19891989
pass
19901990
else:
1991-
self.msg.signature_incompatible_with_supertype(defn.name, name, base.name, context)
1991+
self.msg.signature_incompatible_with_supertype(defn.name, name, base.name, context, original_type, typ)
19921992
return False
19931993

19941994
def bind_and_map_method(

mypy/messages.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,13 +1136,15 @@ def signature_incompatible_with_supertype(
11361136
name_in_super: str,
11371137
supertype: str,
11381138
context: Context,
1139-
original: FunctionLike | None = None,
1140-
override: FunctionLike | None = None,
1139+
original: ProperType,
1140+
override: ProperType,
11411141
) -> None:
11421142
code = codes.OVERRIDE
11431143
target = self.override_target(name, name_in_super, supertype)
11441144
self.fail(f'Signature of "{name}" incompatible with {target}', context, code=code)
11451145

1146+
original_str, override_str = format_type_distinctly(original, override, options=self.options, bare=True)
1147+
11461148
INCLUDE_DECORATOR = True # Include @classmethod and @staticmethod decorators, if any
11471149
ALLOW_DUPS = True # Allow duplicate notes, needed when signatures are duplicates
11481150
ALIGN_OFFSET = 1 # One space, to account for the difference between error and note
@@ -1152,13 +1154,8 @@ def signature_incompatible_with_supertype(
11521154
# note: def f(self) -> str
11531155
# note: Subclass:
11541156
# note: def f(self, x: str) -> None
1155-
if (
1156-
original is not None
1157-
and isinstance(original, (CallableType, Overloaded))
1158-
and override is not None
1159-
and isinstance(override, (CallableType, Overloaded))
1160-
):
1161-
self.note("Superclass:", context, offset=ALIGN_OFFSET + OFFSET, code=code)
1157+
self.note("Superclass:", context, offset=ALIGN_OFFSET + OFFSET, code=code)
1158+
if isinstance(original, (CallableType, Overloaded)):
11621159
self.pretty_callable_or_overload(
11631160
original,
11641161
context,
@@ -1167,8 +1164,16 @@ def signature_incompatible_with_supertype(
11671164
allow_dups=ALLOW_DUPS,
11681165
code=code,
11691166
)
1167+
else:
1168+
self.note(
1169+
original_str,
1170+
context,
1171+
offset=ALIGN_OFFSET + 2 * OFFSET,
1172+
code=code,
1173+
)
11701174

1171-
self.note("Subclass:", context, offset=ALIGN_OFFSET + OFFSET, code=code)
1175+
self.note("Subclass:", context, offset=ALIGN_OFFSET + OFFSET, code=code)
1176+
if isinstance(override, (CallableType, Overloaded)):
11721177
self.pretty_callable_or_overload(
11731178
override,
11741179
context,
@@ -1177,6 +1182,13 @@ def signature_incompatible_with_supertype(
11771182
allow_dups=ALLOW_DUPS,
11781183
code=code,
11791184
)
1185+
else:
1186+
self.note(
1187+
override_str,
1188+
context,
1189+
offset=ALIGN_OFFSET + 2 * OFFSET,
1190+
code=code,
1191+
)
11801192

11811193
def pretty_callable_or_overload(
11821194
self,

0 commit comments

Comments
 (0)