File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3- from functools import cached_property , wraps
3+ from functools import cache , cached_property , wraps
44from typing import Callable , TypeVar
55from typing_extensions import ParamSpec , assert_type
66
77P = ParamSpec ("P" )
88T_co = TypeVar ("T_co" , covariant = True )
99
10+ #
11+ # Tests for @wraps
12+ #
1013
1114def my_decorator (func : Callable [P , T_co ]) -> Callable [P , T_co ]:
1215 @wraps (func )
@@ -53,6 +56,26 @@ def func_wrapper(x: int) -> None: ...
5356 # Wrapper().method(3)
5457 func_wrapper (3 )
5558
59+ #
60+ # Tests for @cache
61+ #
62+
63+ @cache
64+ def check_cached (x : int ) -> int :
65+ return x * 2
66+
67+
68+ assert_type (check_cached (3 ), int )
69+ # Type checkers should check the argument type, but this is currently not
70+ # possible. See https://github.com/python/typeshed/issues/6347 and
71+ # https://github.com/python/typeshed/issues/11280.
72+ # check_cached("invalid") # type: ignore
73+
74+ assert_type (check_cached .cache_info ().misses , int )
75+
76+ #
77+ # Tests for @cached_property
78+ #
5679
5780class A :
5881 def __init__ (self , x : int ):
You can’t perform that action at this time.
0 commit comments