Skip to content

Commit 891ba8b

Browse files
ShaharNavehyouknowone
authored andcommitted
Update shelve.py from 3.13.11
1 parent 4ffafb8 commit 891ba8b

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Lib/shelve.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
the persistent dictionary on disk, if feasible).
5757
"""
5858

59-
from pickle import Pickler, Unpickler
59+
from pickle import DEFAULT_PROTOCOL, Pickler, Unpickler
6060
from io import BytesIO
6161

6262
import collections.abc
@@ -85,7 +85,7 @@ def __init__(self, dict, protocol=None, writeback=False,
8585
keyencoding="utf-8"):
8686
self.dict = dict
8787
if protocol is None:
88-
protocol = 3
88+
protocol = DEFAULT_PROTOCOL
8989
self._protocol = protocol
9090
self.writeback = writeback
9191
self.cache = {}
@@ -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.

0 commit comments

Comments
 (0)