Skip to content

Commit 616ccb5

Browse files
committed
Allow deque length limits to be removed consistently
Constraint: Preserve existing supported Python syntax and public API behavior. Confidence: high Scope-risk: narrow Tested: 180 core and persistent tests passed; real database reopen and bounded/unbounded transitions Not-tested: Other Python versions and operating systems.
1 parent ebfa37c commit 616ccb5

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎diskcache/persistent.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def maxlen(self, value):
136136
"""Set max length of the deque.
137137
138138
Pops items from left while length greater than max.
139+
Set to None to remove the length limit.
139140
140141
>>> deque = Deque()
141142
>>> deque.extendleft('abcde')
@@ -146,7 +147,7 @@ def maxlen(self, value):
146147
:param value: max length
147148
148149
"""
149-
self._maxlen = value
150+
self._maxlen = float('inf') if value is None else value
150151
with self._cache.transact(retry=True):
151152
while len(self._cache) > self._maxlen:
152153
self._popleft()

‎tests/test_deque.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,14 @@ def test_peek(deque):
312312
assert len(deque) == 1
313313
assert deque.peek() == value
314314
assert len(deque) == 1
315+
316+
317+
def test_maxlen_can_be_reset_to_unlimited(tmp_path):
318+
with dc.Cache(str(tmp_path), eviction_policy='none') as cache:
319+
deque = dc.Deque.fromcache(cache, 'abc', maxlen=3)
320+
321+
deque.maxlen = None
322+
323+
deque.extend('def')
324+
assert list(deque) == list('abcdef')
325+
assert deque.maxlen == float('inf')

0 commit comments

Comments
 (0)