Skip to content

Commit 6a7dfe0

Browse files
committed
refactor: get rid of the memberaccess parameter
1 parent 966ac8b commit 6a7dfe0

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

mypy/checker.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,8 +2856,8 @@ def visit_import_from(self, node: ImportFrom) -> None:
28562856
if (sym := self.globals.get(name)) is not None:
28572857
if isinstance(sym.node, TypeInfo):
28582858
self.warn_deprecated(sym.node, node)
2859-
elif isinstance(co := get_proper_type(sym.type), (CallableType, Overloaded)):
2860-
self.warn_deprecated(co, node)
2859+
elif isinstance(typ := get_proper_type(sym.type), (CallableType, Overloaded)):
2860+
self.warn_deprecated(typ, node)
28612861
self.check_import(node)
28622862

28632863
def visit_import_all(self, node: ImportAll) -> None:
@@ -2954,7 +2954,7 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
29542954
and isinstance(var := lvalue.node, Var)
29552955
and isinstance(instance := get_proper_type(var.type), Instance)
29562956
):
2957-
self.check_deprecated_class(instance.type, s, False)
2957+
self.check_deprecated_class(instance.type, s)
29582958

29592959
# Avoid type checking type aliases in stubs to avoid false
29602960
# positives about modern type syntax available in stubs such
@@ -4700,7 +4700,8 @@ def visit_operator_assignment_stmt(self, s: OperatorAssignmentStmt) -> None:
47004700
if inplace:
47014701
# There is __ifoo__, treat as x = x.__ifoo__(y)
47024702
rvalue_type, method_type = self.expr_checker.check_op(method, lvalue_type, s.rvalue, s)
4703-
self.check_deprecated_function(method_type, s, True)
4703+
if isinstance(method_type := get_proper_type(method_type), (CallableType, Overloaded)):
4704+
self.warn_deprecated(method_type, s)
47044705
if not is_subtype(rvalue_type, lvalue_type):
47054706
self.msg.incompatible_operator_assignment(s.op, s)
47064707
else:
@@ -7595,19 +7596,15 @@ def get_deprecation_warning(
75957596
return f"{name} is deprecated: {deprecation}"
75967597
return f"{name} is deprecated [overload {typ}]: {deprecation}"
75977598

7598-
def check_deprecated_function(self, typ: Type, context: Context, memberaccess: bool) -> None:
7599+
def check_deprecated_function(self, typ: Type, context: Context) -> None:
75997600
if isinstance(typ := get_proper_type(typ), (CallableType, Overloaded)):
7600-
self._check_deprecated(typ, context, memberaccess)
7601+
self._check_deprecated(typ, context)
76017602

7602-
def check_deprecated_class(self, typ: TypeInfo, context: Context, memberaccess: bool) -> None:
7603-
self._check_deprecated(typ, context, memberaccess)
7603+
def check_deprecated_class(self, typ: TypeInfo, context: Context) -> None:
7604+
self._check_deprecated(typ, context)
76047605

7605-
def _check_deprecated(
7606-
self, typ: CallableType | Overloaded | TypeInfo, context: Context, memberaccess: bool
7607-
) -> None:
7608-
if memberaccess:
7609-
self.warn_deprecated(typ, context)
7610-
elif typ.deprecated is not None:
7606+
def _check_deprecated(self, typ: CallableType | Overloaded | TypeInfo, context: Context) -> None:
7607+
if typ.deprecated is not None:
76117608
for imp in self.tree.imports:
76127609
if isinstance(imp, ImportFrom) and any(typ.name == n[0] for n in imp.names):
76137610
break

mypy/checkexpr.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ def visit_name_expr(self, e: NameExpr) -> Type:
356356
result = self.analyze_ref_expr(e)
357357
narrowed = self.narrow_type_from_binder(e, result)
358358
if isinstance(e.node, TypeInfo):
359-
self.chk.check_deprecated_class(e.node, e, False)
359+
self.chk.check_deprecated_class(e.node, e)
360360
else:
361-
self.chk.check_deprecated_function(narrowed, e, False)
361+
self.chk.check_deprecated_function(narrowed, e)
362362
return narrowed
363363

364364
def analyze_ref_expr(self, e: RefExpr, lvalue: bool = False) -> Type:
@@ -1479,7 +1479,7 @@ def check_call_expr_with_callee_type(
14791479
callable_name=callable_name,
14801480
object_type=object_type,
14811481
)
1482-
self.chk.check_deprecated_function(callee_type, e, False)
1482+
self.chk.check_deprecated_function(callee_type, e)
14831483
proper_callee = get_proper_type(callee_type)
14841484
if isinstance(e.callee, RefExpr) and isinstance(proper_callee, CallableType):
14851485
# Cache it for find_isinstance_check()
@@ -3260,9 +3260,9 @@ def visit_member_expr(self, e: MemberExpr, is_lvalue: bool = False) -> Type:
32603260
result = self.analyze_ordinary_member_access(e, is_lvalue)
32613261
narrowed = self.narrow_type_from_binder(e, result)
32623262
if isinstance(e.node, TypeInfo):
3263-
self.chk.check_deprecated_class(e.node, e, True)
3264-
else:
3265-
self.chk.check_deprecated_function(narrowed, e, True)
3263+
self.chk.warn_deprecated(e.node, e)
3264+
elif isinstance(typ := get_proper_type(narrowed), (CallableType, Overloaded)):
3265+
self.chk.warn_deprecated(typ, e)
32663266
return narrowed
32673267

32683268
def analyze_ordinary_member_access(self, e: MemberExpr, is_lvalue: bool) -> Type:
@@ -3488,7 +3488,7 @@ def visit_op_expr(self, e: OpExpr) -> Type:
34883488
else:
34893489
assert_never(use_reverse)
34903490
e.method_type = method_type
3491-
self.chk.check_deprecated_function(method_type, e, False)
3491+
self.chk.check_deprecated_function(method_type, e)
34923492
return result
34933493
else:
34943494
raise RuntimeError(f"Unknown operator {e.op}")
@@ -3805,7 +3805,8 @@ def check_method_call_by_name(
38053805
chk=self.chk,
38063806
in_literal_context=self.is_literal_context(),
38073807
)
3808-
self.chk.check_deprecated_function(method_type, context, True)
3808+
if isinstance(mt := get_proper_type(method_type), (CallableType, Overloaded)):
3809+
self.chk.warn_deprecated(mt, context)
38093810
return self.check_method_call(method, base_type, method_type, args, arg_kinds, context)
38103811

38113812
def check_union_method_call_by_name(

0 commit comments

Comments
 (0)