Skip to content

Commit e3f2bee

Browse files
committed
Add a few tests for @cached
1 parent ea4ae21 commit e3f2bee

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

stdlib/@tests/test_cases/check_functools.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from __future__ import annotations
22

3-
from functools import cached_property, wraps
3+
from functools import cache, cached_property, wraps
44
from typing import Callable, TypeVar
55
from typing_extensions import ParamSpec, assert_type
66

77
P = ParamSpec("P")
88
T_co = TypeVar("T_co", covariant=True)
99

10+
#
11+
# Tests for @wraps
12+
#
1013

1114
def 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

5780
class A:
5881
def __init__(self, x: int):

0 commit comments

Comments
 (0)