Skip to content

Commit ed09c46

Browse files
committed
update message to use __init__
1 parent 5b46b6a commit ed09c46

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

mypy/messages.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,6 @@ def no_variant_matches_arguments(
11231123
context,
11241124
code=code,
11251125
)
1126-
11271126
self.note(f"Possible overload variant{plural_s(len(overload.items))}:", context, code=code)
11281127
for item in overload.items:
11291128
self.note(pretty_callable(item, self.options), context, offset=4, code=code)
@@ -3015,7 +3014,14 @@ def [T <: int] f(self, x: int, y: T) -> None
30153014
if s:
30163015
s = ", " + s
30173016
s = first_arg + s
3018-
s = f"{tp.name.split()[0]}({s})" # skip "of Class" part
3017+
if (
3018+
isinstance(definition, FuncDef)
3019+
and hasattr(definition, "name")
3020+
and definition.name == "__init__"
3021+
):
3022+
s = f"{definition.name}({s})"
3023+
else:
3024+
s = f"{tp.name.split()[0]}({s})" # skip "of Class" part
30193025
else:
30203026
s = f"({s})"
30213027

test-data/unit/check-serialize.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ class A:
312312
[out2]
313313
tmp/a.py:2: error: No overload variant of "A" matches argument type "object"
314314
tmp/a.py:2: note: Possible overload variants:
315-
tmp/a.py:2: note: def A(self, x: int) -> A
316-
tmp/a.py:2: note: def A(self, x: str) -> A
315+
tmp/a.py:2: note: def __init__(self, x: int) -> A
316+
tmp/a.py:2: note: def __init__(self, x: str) -> A
317317
tmp/a.py:7: error: No overload variant of "__init__" of "A" matches argument type "object"
318318
tmp/a.py:7: note: Possible overload variants:
319319
tmp/a.py:7: note: def __init__(self, x: int) -> None

0 commit comments

Comments
 (0)