summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/shelve.py7
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS.d/next/Library/2023-07-22-21-57-34.gh-issue-107089.Dnget2.rst2
3 files changed, 10 insertions, 0 deletions
diff --git a/Lib/shelve.py b/Lib/shelve.py
index e053c39..5058471 100644
--- a/Lib/shelve.py
+++ b/Lib/shelve.py
@@ -226,6 +226,13 @@ class DbfilenameShelf(Shelf):
import dbm
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
+ def clear(self):
+ """Remove all items from the shelf."""
+ # Call through to the clear method on dbm-backed shelves.
+ # see https://github.com/python/cpython/issues/107089
+ self.cache.clear()
+ self.dict.clear()
+
def open(filename, flag='c', protocol=None, writeback=False):
"""Open a persistent dictionary for reading and writing.
diff --git a/Misc/ACKS b/Misc/ACKS
index fadf488..8b8c5ad 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -289,6 +289,7 @@ Edward Catmur
Lorenzo M. Catucci
Bruno Cauet
Donn Cave
+James Cave
Charles Cazabon
Jesús Cea Avión
Per Cederqvist
diff --git a/Misc/NEWS.d/next/Library/2023-07-22-21-57-34.gh-issue-107089.Dnget2.rst b/Misc/NEWS.d/next/Library/2023-07-22-21-57-34.gh-issue-107089.Dnget2.rst
new file mode 100644
index 0000000..9d5ba1a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-07-22-21-57-34.gh-issue-107089.Dnget2.rst
@@ -0,0 +1,2 @@
+Shelves opened with :func:`shelve.open` have a much faster :meth:`clear`
+method. Patch by James Cave. \ No newline at end of file