File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -1215,6 +1215,12 @@ def _resolve_funcitem_from_decorator(dec: nodes.OverloadPart) -> nodes.FuncItem
1215
1215
def apply_decorator_to_funcitem (
1216
1216
decorator : nodes .Expression , func : nodes .FuncItem
1217
1217
) -> nodes .FuncItem | None :
1218
+ if (
1219
+ isinstance (decorator , nodes .CallExpr )
1220
+ and isinstance (decorator .callee , nodes .RefExpr )
1221
+ and decorator .callee .fullname in mypy .types .DEPRECATED_TYPE_NAMES
1222
+ ):
1223
+ return func
1218
1224
if not isinstance (decorator , nodes .RefExpr ):
1219
1225
return None
1220
1226
if not decorator .fullname :
@@ -1223,6 +1229,7 @@ def apply_decorator_to_funcitem(
1223
1229
if (
1224
1230
decorator .fullname in ("builtins.staticmethod" , "abc.abstractmethod" )
1225
1231
or decorator .fullname in mypy .types .OVERLOAD_NAMES
1232
+ or decorator .fullname in mypy .types .FINAL_DECORATOR_NAMES
1226
1233
):
1227
1234
return func
1228
1235
if decorator .fullname == "builtins.classmethod" :
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ class Sequence(Iterable[_T_co]): ...
71
71
class Tuple(Sequence[_T_co]): ...
72
72
class NamedTuple(tuple[Any, ...]): ...
73
73
def overload(func: _T) -> _T: ...
74
+ def deprecated(__msg: str) -> Callable[[_T], _T]: ...
75
+ def final(func: _T) -> _T: ...
74
76
"""
75
77
76
78
stubtest_builtins_stub = """
@@ -630,6 +632,23 @@ def f5(__b: str) -> str: ...
630
632
runtime = "def f5(x, /): pass" ,
631
633
error = None ,
632
634
)
635
+ yield Case (
636
+ stub = """
637
+ from typing import deprecated, final
638
+ class Foo:
639
+ @overload
640
+ @final
641
+ def f6(self, __a: int) -> int: ...
642
+ @overload
643
+ @deprecated("evil")
644
+ def f6(self, __b: str) -> str: ...
645
+ """ ,
646
+ runtime = """
647
+ class Foo:
648
+ def f6(self, x, /): pass
649
+ """ ,
650
+ error = None ,
651
+ )
633
652
634
653
@collect_cases
635
654
def test_property (self ) -> Iterator [Case ]:
Original file line number Diff line number Diff line change 119
119
# Supported Annotated type names.
120
120
ANNOTATED_TYPE_NAMES : Final = ("typing.Annotated" , "typing_extensions.Annotated" )
121
121
122
+ # Supported @deprecated type names
123
+ DEPRECATED_TYPE_NAMES : Final = ("typing.deprecated" , "typing_extensions.deprecated" )
124
+
122
125
# We use this constant in various places when checking `tuple` subtyping:
123
126
TUPLE_LIKE_INSTANCE_NAMES : Final = (
124
127
"builtins.tuple" ,
You can’t perform that action at this time.
0 commit comments