bpo-34204: Use pickle.DEFAULT_PROTOCOL in shelve (GH-19639)
Use pickle.DEFAULT_PROTOCOL (currently 5) in shelve instead of a
hardcoded 3.
diff --git a/Lib/shelve.py b/Lib/shelve.py
index 5d443a0..e053c39 100644
--- a/Lib/shelve.py
+++ b/Lib/shelve.py
@@ -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
@@ -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 = {}
diff --git a/Lib/test/test_shelve.py b/Lib/test/test_shelve.py
index ac25eee..cfdd67c 100644
--- a/Lib/test/test_shelve.py
+++ b/Lib/test/test_shelve.py
@@ -1,6 +1,8 @@
import unittest
import shelve
import glob
+import pickle
+
from test import support
from test.support import os_helper
from collections.abc import MutableMapping
@@ -160,7 +162,7 @@ def test_with(self):
def test_default_protocol(self):
with shelve.Shelf({}) as s:
- self.assertEqual(s._protocol, 3)
+ self.assertEqual(s._protocol, pickle.DEFAULT_PROTOCOL)
from test import mapping_tests