Skip to content

Commit

Permalink
fix signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
tyralla committed Nov 2, 2024
1 parent 157c7c9 commit 281902e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
25 changes: 14 additions & 11 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4495,7 +4495,7 @@ def check_member_assignment(
# Search for possible deprecations:
mx.chk.check_deprecated(dunder_set, mx.context)
mx.chk.warn_deprecated_overload_item(
dunder_set, mx.context, inferred_dunder_set_type, attribute_type
dunder_set, mx.context, target=inferred_dunder_set_type, selftype=attribute_type
)

# In the following cases, a message already will have been recorded in check_call.
Expand Down Expand Up @@ -7669,7 +7669,7 @@ def has_valid_attribute(self, typ: Type, name: str) -> bool:
def get_expression_type(self, node: Expression, type_context: Type | None = None) -> Type:
return self.expr_checker.accept(node, type_context=type_context)

def check_deprecated(self, node: SymbolNode | None, context: Context) -> None:
def check_deprecated(self, node: Node | None, context: Context) -> None:
"""Warn if deprecated and not directly imported with a `from` statement."""
if isinstance(node, Decorator):
node = node.func
Expand All @@ -7682,7 +7682,7 @@ def check_deprecated(self, node: SymbolNode | None, context: Context) -> None:
else:
self.warn_deprecated(node, context)

def warn_deprecated(self, node: SymbolNode | None, context: Context) -> None:
def warn_deprecated(self, node: Node | None, context: Context) -> None:
"""Warn if deprecated."""
if isinstance(node, Decorator):
node = node.func
Expand All @@ -7696,18 +7696,21 @@ def warn_deprecated(self, node: SymbolNode | None, context: Context) -> None:

def warn_deprecated_overload_item(
self,
node: SymbolNode | None,
node: Node | None,
context: Context,
target: CallableType,
instance: Instance | None = None,
*,
target: Type,
selftype: Type | None = None,
) -> None:
"""Warn if the overload item corresponding to the given callable is deprecated."""
if isinstance(node, OverloadedFuncDef):
target = get_proper_type(target)
if isinstance(node, OverloadedFuncDef) and isinstance(target, CallableType):
for item in node.items:
if isinstance(item, Decorator):
candidate = item.func.type
if instance is not None:
candidate = bind_self(candidate, instance)
if isinstance(item, Decorator) and isinstance(
candidate := item.func.type, CallableType
):
if selftype is not None:
candidate = bind_self(candidate, selftype)
if candidate == target:
self.warn_deprecated(item.func, context)

Expand Down
2 changes: 1 addition & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ def check_call_expr_with_callee_type(
)
proper_callee = get_proper_type(callee_type)
if isinstance(e.callee, NameExpr):
self.chk.warn_deprecated_overload_item(e.callee.node, e, callee_type)
self.chk.warn_deprecated_overload_item(e.callee.node, e, target=callee_type)
if isinstance(e.callee, RefExpr) and isinstance(proper_callee, CallableType):
# Cache it for find_isinstance_check()
if proper_callee.type_guard is not None:
Expand Down
2 changes: 1 addition & 1 deletion mypy/checkmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def analyze_descriptor_access(
if not assignment:
mx.chk.check_deprecated(dunder_get, mx.context)
mx.chk.warn_deprecated_overload_item(
dunder_get, mx.context, inferred_dunder_get_type, descriptor_type
dunder_get, mx.context, target=inferred_dunder_get_type, selftype=descriptor_type
)

inferred_dunder_get_type = get_proper_type(inferred_dunder_get_type)
Expand Down

0 comments on commit 281902e

Please sign in to comment.