184184)
185185from mypy .types import (
186186 ANY_STRATEGY ,
187- DEPRECATED_TYPE_NAMES ,
188187 MYPYC_NATIVE_INT_NAMES ,
189188 OVERLOAD_NAMES ,
190189 AnyType ,
@@ -637,10 +636,6 @@ def _visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
637636 if len (defn .items ) == 1 :
638637 self .fail (message_registry .MULTIPLE_OVERLOADS_REQUIRED , defn )
639638
640- for item in defn .items :
641- if isinstance (item , Decorator ) and isinstance (ct := item .func .type , CallableType ):
642- self .create_deprecation_warning (ct , item .decorators )
643-
644639 if defn .is_property :
645640 # HACK: Infer the type of the property.
646641 assert isinstance (defn .items [0 ], Decorator )
@@ -659,17 +654,6 @@ def _visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
659654 self .fail (message_registry .INCONSISTENT_ABSTRACT_OVERLOAD , defn )
660655 if defn .impl :
661656 defn .impl .accept (self )
662- if (
663- isinstance (defn .impl , Decorator )
664- and isinstance (defn .impl .func .type , CallableType )
665- and ((deprecated := defn .impl .func .type .deprecated ) is not None )
666- ):
667- if isinstance (defn .type , (CallableType , Overloaded )):
668- defn .type .deprecated = deprecated
669- for subdef in defn .items :
670- type_ = get_proper_type (subdef .type )
671- if isinstance (type_ , (CallableType , Overloaded )):
672- type_ .deprecated = deprecated
673657 if not defn .is_property :
674658 self .check_overlapping_overloads (defn )
675659 if defn .type is None :
@@ -2422,7 +2406,6 @@ def check__exit__return_type(self, defn: FuncItem) -> None:
24222406 def visit_class_def (self , defn : ClassDef ) -> None :
24232407 """Type check a class definition."""
24242408 typ = defn .info
2425- self .create_deprecation_warning (typ , defn .decorators )
24262409 for base in typ .mro [1 :]:
24272410 if base .is_final :
24282411 self .fail (message_registry .CANNOT_INHERIT_FROM_FINAL .format (base .name ), defn )
@@ -5027,8 +5010,6 @@ def visit_del_stmt(self, s: DelStmt) -> None:
50275010 )
50285011
50295012 def visit_decorator (self , e : Decorator ) -> None :
5030- if isinstance (ct := e .func .type , CallableType ):
5031- self .create_deprecation_warning (ct , e .decorators )
50325013 for d in e .decorators :
50335014 if isinstance (d , RefExpr ):
50345015 if d .fullname == "typing.no_type_check" :
@@ -7556,52 +7537,6 @@ def has_valid_attribute(self, typ: Type, name: str) -> bool:
75567537 def get_expression_type (self , node : Expression , type_context : Type | None = None ) -> Type :
75577538 return self .expr_checker .accept (node , type_context = type_context )
75587539
7559- def create_deprecation_warning (
7560- self , typ : CallableType | Overloaded | TypeInfo , decorators : Iterable [Expression ]
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."""
7564-
7565- if isinstance (typ , CallableType ):
7566- if (defn := typ .definition ) is None :
7567- name = f"function { typ .name } "
7568- else :
7569- name = f"function { defn .fullname } "
7570- elif isinstance (typ , Overloaded ):
7571- if isinstance (func := typ .items [0 ].definition , FuncDef ):
7572- name = f"function { func .fullname } "
7573- else :
7574- name = f"function { typ .name } "
7575- else :
7576- name = f"class { typ .fullname } "
7577-
7578- overload = False
7579- deprecation : str | None = None
7580- for decorator in decorators :
7581- if (
7582- isinstance (typ , CallableType )
7583- and isinstance (decorator , NameExpr )
7584- and (decorator .fullname in OVERLOAD_NAMES )
7585- ):
7586- overload = True
7587- if deprecation is not None :
7588- self .msg .note ("@overload should be placed before @deprecated" , decorator )
7589- elif (
7590- isinstance (decorator , CallExpr )
7591- and isinstance (callee := decorator .callee , NameExpr )
7592- and (callee .fullname in DEPRECATED_TYPE_NAMES )
7593- and (len (args := decorator .args ) >= 1 )
7594- and isinstance (arg := args [0 ], StrExpr )
7595- and ((value := arg .value ) is not None )
7596- ):
7597- deprecation = value
7598-
7599- if deprecation is not None :
7600- if overload :
7601- typ .deprecated = f"overload { typ } of { name } is deprecated: { deprecation } "
7602- else :
7603- typ .deprecated = f"{ name } is deprecated: { deprecation } "
7604-
76057540 def check_deprecated (
76067541 self , typ : CallableType | Overloaded | TypeInfo , context : Context
76077542 ) -> None :
0 commit comments