Skip to content

Commit cd60ff8

Browse files
committed
Add @lru_cache tests
1 parent 72db897 commit cd60ff8

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

stdlib/@tests/test_cases/check_functools.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

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

@@ -64,17 +64,43 @@ def func_wrapper(x: int) -> None: ...
6464

6565

6666
@cache
67-
def check_cached(x: int) -> int:
67+
def check_cache(x: int) -> int:
6868
return x * 2
6969

7070

71-
assert_type(check_cached(3), int)
71+
assert_type(check_cache(3), int)
7272
# Type checkers should check the argument type, but this is currently not
7373
# possible. See https://github.com/python/typeshed/issues/6347 and
7474
# https://github.com/python/typeshed/issues/11280.
7575
# check_cached("invalid") # xtype: ignore
7676

77-
assert_type(check_cached.cache_info().misses, int)
77+
assert_type(check_cache.cache_info().misses, int)
78+
79+
80+
#
81+
# Tests for @lru_cache
82+
#
83+
84+
85+
@lru_cache
86+
def check_lru_cache(x: int) -> int:
87+
return x * 2
88+
89+
@lru_cache(maxsize=32)
90+
def check_lru_cache_with_maxsize(x: int) -> int:
91+
return x * 2
92+
93+
assert_type(check_lru_cache(3), int)
94+
assert_type(check_lru_cache_with_maxsize(3), int)
95+
# Type checkers should check the argument type, but this is currently not
96+
# possible. See https://github.com/python/typeshed/issues/6347 and
97+
# https://github.com/python/typeshed/issues/11280.
98+
# check_lru_cache("invalid") # xtype: ignore
99+
# check_lru_cache_with_maxsize("invalid") # xtype: ignore
100+
101+
assert_type(check_lru_cache.cache_info().misses, int)
102+
assert_type(check_lru_cache_with_maxsize.cache_info().misses, int)
103+
78104

79105
#
80106
# Tests for @cached_property

0 commit comments

Comments
 (0)