Skip to content

Commit c95f936

Browse files
committed
execute check_deprecated before warn_deprecated_overload_item when analysing "normal" methods (like we do when in other cases).
1 parent cc7a915 commit c95f936

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

mypy/checkexpr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,7 @@ def check_call_expr_with_callee_type(
14911491
if (symbol := base.names.get(member)) is not None:
14921492
node = symbol.node
14931493
break
1494+
self.chk.check_deprecated(node, e)
14941495
self.chk.warn_deprecated_overload_item(
14951496
node, e, target=callee_type, selftype=object_type
14961497
)

test-data/unit/check-deprecated.test

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,29 +402,34 @@ class A:
402402
def h(self, v: int) -> A: ...
403403
@overload
404404
def h(self, v: str) -> A: ...
405-
@deprecated("use `h2` instead")
405+
@deprecated("use `h2` instead")
406406
def h(self, v: Union[int, str]) -> A: ...
407407

408408
class B(A): ...
409409

410+
int_or_str: Union[int, str]
411+
410412
a = A()
411413
a.f(1) # E: overload def (self: __main__.A, v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead
412414
a.f("x")
413-
414-
int_or_str: Union[int, str]
415-
a.f(int_or_str)
415+
a.f(int_or_str) # E: overload def (self: __main__.A, v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead
416416
a.g(1)
417417
a.g("x") # E: overload def (self: __main__.A, v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead
418-
a.h(1) # E: function __main__.A.h is deprecated: use `h2` instead
419-
a.h("x") # E: function __main__.A.h is deprecated: use `h2` instead
418+
a.g(int_or_str) # E: overload def (self: __main__.A, v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead
419+
a.h(1) # E: function __main__.A.h is deprecated: use `h2` instead
420+
a.h("x") # E: function __main__.A.h is deprecated: use `h2` instead
421+
a.h(int_or_str) # E: function __main__.A.h is deprecated: use `h2` instead
420422

421423
b = B()
422424
b.f(1) # E: overload def (self: __main__.A, v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead
423425
b.f("x")
426+
b.f(int_or_str) # E: overload def (self: __main__.A, v: builtins.int) of function __main__.A.f is deprecated: pass `str` instead
424427
b.g(1)
425428
b.g("x") # E: overload def (self: __main__.A, v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead
426-
b.h(1) # E: function __main__.A.h is deprecated: use `h2` instead
427-
b.h("x") # E: function __main__.A.h is deprecated: use `h2` instead
429+
b.g(int_or_str) # E: overload def (self: __main__.A, v: builtins.str) of function __main__.A.g is deprecated: pass `int` instead
430+
b.h(1) # E: function __main__.A.h is deprecated: use `h2` instead
431+
b.h("x") # E: function __main__.A.h is deprecated: use `h2` instead
432+
b.h(int_or_str) # E: function __main__.A.h is deprecated: use `h2` instead
428433

429434
[builtins fixtures/tuple.pyi]
430435

0 commit comments

Comments
 (0)