Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,26 @@ def cached_func():
assert isinstance(cached_func, type_entity), "lru_cache should not be using the python-based version"


def test_functools_lru_cache_typed_truthiness():
from functools import lru_cache

@lru_cache(maxsize=2, typed="x")
def typed_func(a, b):
return a

typed_func(1, 2)
typed_func(1.0, 2)
assert typed_func.cache_info().misses == 2

@lru_cache(maxsize=2, typed="")
def untyped_func(a, b):
return a

untyped_func(1, 2)
untyped_func(1.0, 2)
assert untyped_func.cache_info().misses == 1


def test_no_docstring():
def no_doc():
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
@Slot(value = SlotKind.tp_new, isComplex = true)
@SlotSignature(name = "lru_cache", minNumOfPositionalArgs = 5, takesVarArgs = true, takesVarKeywordArgs = true, //
parameterNames = {"$cls", "user_function", "maxsize", "typed", "cache_info_type"})
@ArgumentClinic(name = "typed", conversion = ClinicConversion.Int)
@ArgumentClinic(name = "typed", conversion = ClinicConversion.Boolean)
@GenerateNodeFactory
protected abstract static class LruCacheNewNode extends PythonClinicBuiltinNode {

Expand All @@ -131,7 +131,7 @@ protected ArgumentClinicProvider getArgumentClinic() {

@Specialization
static Object lruCacheNew(VirtualFrame frame, Object type,
Object func, Object maxsize_O, int typed, Object cache_info_type,
Object func, Object maxsize_O, boolean typed, Object cache_info_type,
@Bind Node inliningTarget,
@Cached PyCallableCheckNode callableCheck,
@Cached PyIndexCheckNode indexCheck,
Expand Down Expand Up @@ -170,7 +170,7 @@ static Object lruCacheNew(VirtualFrame frame, Object type,
obj.root.prev = obj.root;
obj.root.next = obj.root;
obj.wrapper = wrapper;
obj.typed = typed;
obj.typed = typed ? 1 : 0;
// obj.cache = new ObjectHashMap();

obj.func = func;
Expand Down