Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1bc82f8

Browse files
committed
Removed deprecated method arguments from the shelve module.
1 parent 7cf9ce2 commit 1bc82f8

4 files changed

Lines changed: 25 additions & 34 deletions

File tree

Doc/lib/libshelve.tex

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ \section{\module{shelve} ---
1313
sub-objects. The keys are ordinary strings.
1414
\refstmodindex{pickle}
1515

16-
\begin{funcdesc}{open}{filename\optional{,flag='c'\optional{,protocol=\code{None}\optional{,writeback=\code{False}\optional{,binary=\code{None}}}}}}
16+
\begin{funcdesc}{open}{filename\optional{,flag='c'\optional{,protocol=\code{None}\optional{,writeback=\code{False}}}}}
1717
Open a persistent dictionary. The filename specified is the base filename
1818
for the underlying database. As a side-effect, an extension may be added to
1919
the filename and more than one file may be created. By default, the
@@ -24,8 +24,7 @@ \section{\module{shelve} ---
2424
By default, version 0 pickles are used to serialize values.
2525
The version of the pickle protocol can be specified with the
2626
\var{protocol} parameter. \versionchanged[The \var{protocol}
27-
parameter was added. The \var{binary} parameter is deprecated
28-
and provided for backwards compatibility only]{2.3}
27+
parameter was added]{2.3}
2928

3029
By default, mutations to persistent-dictionary mutable entries are not
3130
automatically written back. If the optional \var{writeback} parameter
@@ -76,24 +75,23 @@ \subsection{Restrictions}
7675

7776
\end{itemize}
7877

79-
\begin{classdesc}{Shelf}{dict\optional{, protocol=None\optional{, writeback=False\optional{, binary=None}}}}
78+
\begin{classdesc}{Shelf}{dict\optional{, protocol=None\optional{, writeback=False}}}
8079
A subclass of \class{UserDict.DictMixin} which stores pickled values in the
8180
\var{dict} object.
8281

8382
By default, version 0 pickles are used to serialize values. The
8483
version of the pickle protocol can be specified with the
8584
\var{protocol} parameter. See the \module{pickle} documentation for a
8685
discussion of the pickle protocols. \versionchanged[The \var{protocol}
87-
parameter was added. The \var{binary} parameter is deprecated and
88-
provided for backwards compatibility only]{2.3}
86+
parameter was added]{2.3}
8987

9088
If the \var{writeback} parameter is \code{True}, the object will hold a
9189
cache of all entries accessed and write them back to the \var{dict} at
9290
sync and close times. This allows natural operations on mutable entries,
9391
but can consume much more memory and make sync and close take a long time.
9492
\end{classdesc}
9593

96-
\begin{classdesc}{BsdDbShelf}{dict\optional{, protocol=None\optional{, writeback=False\optional{, binary=None}}}}
94+
\begin{classdesc}{BsdDbShelf}{dict\optional{, protocol=None\optional{, writeback=False}}}
9795

9896
A subclass of \class{Shelf} which exposes \method{first},
9997
\method{next}, \method{previous}, \method{last} and
@@ -102,19 +100,19 @@ \subsection{Restrictions}
102100
the constructor must support those methods. This is generally
103101
accomplished by calling one of \function{bsddb.hashopen},
104102
\function{bsddb.btopen} or \function{bsddb.rnopen}. The optional
105-
\var{protocol}, \var{writeback}, and \var{binary} parameters have the
103+
\var{protocol} and \var{writeback} parameters have the
106104
same interpretation as for the \class{Shelf} class.
107105

108106
\end{classdesc}
109107

110-
\begin{classdesc}{DbfilenameShelf}{filename\optional{, flag='c'\optional{, protocol=None\optional{, writeback=False\optional{, binary=None}}}}}
108+
\begin{classdesc}{DbfilenameShelf}{filename\optional{, flag='c'\optional{, protocol=None\optional{, writeback=False}}}}
111109

112110
A subclass of \class{Shelf} which accepts a \var{filename} instead of
113111
a dict-like object. The underlying file will be opened using
114112
{}\function{anydbm.open}. By default, the file will be created and
115113
opened for both read and write. The optional \var{flag} parameter has
116114
the same interpretation as for the \function{open} function. The
117-
optional \var{protocol}, \var{writeback}, and \var{binary} parameters
115+
optional \var{protocol} and \var{writeback} parameters
118116
have the same interpretation as for the \class{Shelf} class.
119117

120118
\end{classdesc}

Lib/shelve.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,8 @@ class Shelf(UserDict.DictMixin):
8080
See the module's __doc__ string for an overview of the interface.
8181
"""
8282

83-
def __init__(self, dict, protocol=None, writeback=False, binary=None):
83+
def __init__(self, dict, protocol=None, writeback=False):
8484
self.dict = dict
85-
if protocol is not None and binary is not None:
86-
raise ValueError, "can't specify both 'protocol' and 'binary'"
87-
if binary is not None:
88-
warnings.warn("The 'binary' argument to Shelf() is deprecated",
89-
PendingDeprecationWarning)
90-
protocol = int(binary)
9185
if protocol is None:
9286
protocol = 0
9387
self._protocol = protocol
@@ -171,8 +165,8 @@ class BsdDbShelf(Shelf):
171165
See the module's __doc__ string for an overview of the interface.
172166
"""
173167

174-
def __init__(self, dict, protocol=None, writeback=False, binary=None):
175-
Shelf.__init__(self, dict, protocol, writeback, binary)
168+
def __init__(self, dict, protocol=None, writeback=False):
169+
Shelf.__init__(self, dict, protocol, writeback)
176170

177171
def set_location(self, key):
178172
(key, value) = self.dict.set_location(key)
@@ -207,12 +201,12 @@ class DbfilenameShelf(Shelf):
207201
See the module's __doc__ string for an overview of the interface.
208202
"""
209203

210-
def __init__(self, filename, flag='c', protocol=None, writeback=False, binary=None):
204+
def __init__(self, filename, flag='c', protocol=None, writeback=False):
211205
import anydbm
212-
Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback, binary)
206+
Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback)
213207

214208

215-
def open(filename, flag='c', protocol=None, writeback=False, binary=None):
209+
def open(filename, flag='c', protocol=None, writeback=False):
216210
"""Open a persistent dictionary for reading and writing.
217211
218212
The filename parameter is the base filename for the underlying
@@ -222,10 +216,7 @@ def open(filename, flag='c', protocol=None, writeback=False, binary=None):
222216
anydbm.open(). The optional protocol parameter specifies the
223217
version of the pickle protocol (0, 1, or 2).
224218
225-
The optional binary parameter is deprecated and may be set to True
226-
to force the use of binary pickles for serializing data values.
227-
228219
See the module's __doc__ string for an overview of the interface.
229220
"""
230221

231-
return DbfilenameShelf(filename, flag, protocol, writeback, binary)
222+
return DbfilenameShelf(filename, flag, protocol, writeback)

Lib/test/test_shelve.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class TestCase(unittest.TestCase):
1010

1111
def test_ascii_file_shelf(self):
1212
try:
13-
s = shelve.open(self.fn, binary=False)
13+
s = shelve.open(self.fn, protocol=0)
1414
s['key1'] = (1,2,3,4)
1515
self.assertEqual(s['key1'], (1,2,3,4))
1616
s.close()
@@ -20,7 +20,7 @@ def test_ascii_file_shelf(self):
2020

2121
def test_binary_file_shelf(self):
2222
try:
23-
s = shelve.open(self.fn, binary=True)
23+
s = shelve.open(self.fn, protocol=1)
2424
s['key1'] = (1,2,3,4)
2525
self.assertEqual(s['key1'], (1,2,3,4))
2626
s.close()
@@ -40,12 +40,12 @@ def test_proto2_file_shelf(self):
4040

4141
def test_in_memory_shelf(self):
4242
d1 = {}
43-
s = shelve.Shelf(d1, binary=False)
43+
s = shelve.Shelf(d1, protocol=0)
4444
s['key1'] = (1,2,3,4)
4545
self.assertEqual(s['key1'], (1,2,3,4))
4646
s.close()
4747
d2 = {}
48-
s = shelve.Shelf(d2, binary=True)
48+
s = shelve.Shelf(d2, protocol=1)
4949
s['key1'] = (1,2,3,4)
5050
self.assertEqual(s['key1'], (1,2,3,4))
5151
s.close()
@@ -102,19 +102,19 @@ def tearDown(self):
102102
os.unlink(f)
103103

104104
class TestAsciiFileShelve(TestShelveBase):
105-
_args={'binary':False}
105+
_args={'protocol':0}
106106
_in_mem = False
107107
class TestBinaryFileShelve(TestShelveBase):
108-
_args={'binary':True}
108+
_args={'protocol':1}
109109
_in_mem = False
110110
class TestProto2FileShelve(TestShelveBase):
111111
_args={'protocol':2}
112112
_in_mem = False
113113
class TestAsciiMemShelve(TestShelveBase):
114-
_args={'binary':False}
114+
_args={'protocol':0}
115115
_in_mem = True
116116
class TestBinaryMemShelve(TestShelveBase):
117-
_args={'binary':True}
117+
_args={'protocol':1}
118118
_in_mem = True
119119
class TestProto2MemShelve(TestShelveBase):
120120
_args={'protocol':2}

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Extension Modules
2121
Library
2222
-------
2323

24+
- the shelve module no longer uses the deprecated binary parameter.
25+
2426
- the pstats module no longer uses the deprecated ignore() method.
2527

2628
- the filecmp module no longer uses the deprecated use_statcache argument.

0 commit comments

Comments
 (0)