Skip to content

Commit 7f3d73c

Browse files
committed
fix inheritance
1 parent 2461eff commit 7f3d73c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

mypy/checkexpr.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,10 +1486,11 @@ def check_call_expr_with_callee_type(
14861486
proper_callee = get_proper_type(callee_type)
14871487
if isinstance(e.callee, (NameExpr, MemberExpr)):
14881488
node = e.callee.node
1489-
if (node is None) and (member is not None) and isinstance(object_type, Instance) and (
1490-
(symbol := object_type.type.names.get(member)) is not None
1491-
):
1492-
node = symbol.node
1489+
if (node is None) and (member is not None) and isinstance(object_type, Instance):
1490+
for base in object_type.type.mro:
1491+
if (symbol := base.names.get(member)) is not None:
1492+
node = symbol.node
1493+
break
14931494
self.chk.warn_deprecated_overload_item(
14941495
node, e, target=callee_type, selftype=object_type
14951496
)

test-data/unit/check-deprecated.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ class A:
405405
@deprecated("use `h2` instead")
406406
def h(self, v: Union[int, str]) -> A: ...
407407

408+
class B(A): ...
409+
408410
a = A()
409411
a.f(1) # E: overload def (self: __main__.A, v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead
410412
a.f("x")
@@ -413,6 +415,14 @@ a.g("x") # E: overload def (self: __main__.A, v: builtins.str) of function __ma
413415
a.h(1) # E: function __main__.A.h is deprecated: use `h2` instead
414416
a.h("x") # E: function __main__.A.h is deprecated: use `h2` instead
415417

418+
b = B()
419+
b.f(1) # E: overload def (self: __main__.A, v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead
420+
b.f("x")
421+
b.g(1)
422+
b.g("x") # E: overload def (self: __main__.A, v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead
423+
b.h(1) # E: function __main__.A.h is deprecated: use `h2` instead
424+
b.h("x") # E: function __main__.A.h is deprecated: use `h2` instead
425+
416426
[builtins fixtures/tuple.pyi]
417427

418428

0 commit comments

Comments
 (0)