Skip to content

Commit 1372e66

Browse files
committed
refactor: convert get_deprecation_warning to create_deprecation_warning and document it
1 parent 1a40953 commit 1372e66

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

mypy/checker.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def _visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
639639

640640
for item in defn.items:
641641
if isinstance(item, Decorator) and isinstance(ct := item.func.type, CallableType):
642-
ct.deprecated = self.get_deprecation_warning(ct, item.decorators)
642+
self.create_deprecation_warning(ct, item.decorators)
643643

644644
if defn.is_property:
645645
# HACK: Infer the type of the property.
@@ -2422,7 +2422,7 @@ def check__exit__return_type(self, defn: FuncItem) -> None:
24222422
def visit_class_def(self, defn: ClassDef) -> None:
24232423
"""Type check a class definition."""
24242424
typ = defn.info
2425-
typ.deprecated = self.get_deprecation_warning(typ, defn.decorators)
2425+
self.create_deprecation_warning(typ, defn.decorators)
24262426
for base in typ.mro[1:]:
24272427
if base.is_final:
24282428
self.fail(message_registry.CANNOT_INHERIT_FROM_FINAL.format(base.name), defn)
@@ -5028,7 +5028,7 @@ def visit_del_stmt(self, s: DelStmt) -> None:
50285028

50295029
def visit_decorator(self, e: Decorator) -> None:
50305030
if isinstance(ct := e.func.type, CallableType):
5031-
ct.deprecated = self.get_deprecation_warning(ct, e.decorators)
5031+
self.create_deprecation_warning(ct, e.decorators)
50325032
for d in e.decorators:
50335033
if isinstance(d, RefExpr):
50345034
if d.fullname == "typing.no_type_check":
@@ -7556,9 +7556,11 @@ def has_valid_attribute(self, typ: Type, name: str) -> bool:
75567556
def get_expression_type(self, node: Expression, type_context: Type | None = None) -> Type:
75577557
return self.expr_checker.accept(node, type_context=type_context)
75587558

7559-
def get_deprecation_warning(
7559+
def create_deprecation_warning(
75607560
self, typ: CallableType | Overloaded | TypeInfo, decorators: Iterable[Expression]
7561-
) -> str | None:
7561+
) -> None:
7562+
"""Create a warning when visiting a deprecated (decorated) callable, overload or
7563+
class that may be used later if the deprecated feature is used."""
75627564

75637565
name = typ.name
75647566
if isinstance(typ, CallableType):
@@ -7590,11 +7592,11 @@ def get_deprecation_warning(
75907592
):
75917593
deprecation = value
75927594

7593-
if deprecation is None:
7594-
return None
7595-
if not overload:
7596-
return f"{name} is deprecated: {deprecation}"
7597-
return f"{name} is deprecated [overload {typ}]: {deprecation}"
7595+
if deprecation is not None:
7596+
if overload:
7597+
typ.deprecated = f"{name} is deprecated [overload {typ}]: {deprecation}"
7598+
else:
7599+
typ.deprecated = f"{name} is deprecated: {deprecation}"
75987600

75997601
def check_deprecated(self, typ: CallableType | Overloaded | TypeInfo, context: Context) -> None:
76007602
"""Warn if deprecated and not directly imported with a `from` statement."""

0 commit comments

Comments
 (0)