Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Update shelve.py from 3.13.11
  • Loading branch information
ShaharNaveh authored and youknowone committed Jan 1, 2026
commit 891ba8b0cc1bb674cae5906a2e70c5e0a9097930
11 changes: 9 additions & 2 deletions Lib/shelve.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
the persistent dictionary on disk, if feasible).
"""

from pickle import Pickler, Unpickler
from pickle import DEFAULT_PROTOCOL, Pickler, Unpickler
from io import BytesIO

import collections.abc
Expand Down Expand Up @@ -85,7 +85,7 @@ def __init__(self, dict, protocol=None, writeback=False,
keyencoding="utf-8"):
self.dict = dict
if protocol is None:
protocol = 3
protocol = DEFAULT_PROTOCOL
self._protocol = protocol
self.writeback = writeback
self.cache = {}
Expand Down Expand Up @@ -226,6 +226,13 @@ def __init__(self, filename, flag='c', protocol=None, writeback=False):
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.
Expand Down