Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 810d5d8

Browse filesBrowse files
authored
gh-107089: Improve Shelf.clear method performance (gh-107090)
1 parent 11c055f commit 810d5d8
Copy full SHA for 810d5d8

File tree

Expand file treeCollapse file tree

3 files changed

+10
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+10
-0
lines changed

‎Lib/shelve.py

Copy file name to clipboardExpand all lines: Lib/shelve.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ def __init__(self, filename, flag='c', protocol=None, writeback=False):
226226
import dbm
227227
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
228228

229+
def clear(self):
230+
"""Remove all items from the shelf."""
231+
# Call through to the clear method on dbm-backed shelves.
232+
# see https://github.com/python/cpython/issues/107089
233+
self.cache.clear()
234+
self.dict.clear()
235+
229236

230237
def open(filename, flag='c', protocol=None, writeback=False):
231238
"""Open a persistent dictionary for reading and writing.

‎Misc/ACKS

Copy file name to clipboardExpand all lines: Misc/ACKS
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ Edward Catmur
289289
Lorenzo M. Catucci
290290
Bruno Cauet
291291
Donn Cave
292+
James Cave
292293
Charles Cazabon
293294
Jesús Cea Avión
294295
Per Cederqvist
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Shelves opened with :func:`shelve.open` have a much faster :meth:`clear`
2+
method. Patch by James Cave.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.