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

Skip to content

Commit b9da9bc

Browse files
committed
Start replacing UserDict.DictMixin with collections.MutableMapping (the bsddb modules are next).
1 parent 15ebc88 commit b9da9bc

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

Lib/_abcoll.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ def items(self):
378378
def values(self):
379379
return ValuesView(self)
380380

381+
def __eq__(self, other):
382+
return set(self) == set(other)
383+
384+
def __ne__(self, other):
385+
return set(self) == set(other)
381386

382387
class MappingView(metaclass=ABCMeta):
383388

@@ -485,6 +490,13 @@ def update(self, other=(), **kwds):
485490
for key, value in kwds.items():
486491
self[key] = value
487492

493+
def setdefault(self, key, default=None):
494+
try:
495+
return self[key]
496+
except KeyError:
497+
self[key] = default
498+
return default
499+
488500
MutableMapping.register(dict)
489501

490502

Lib/bsddb/dbshelve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
HIGHEST_PROTOCOL = pickle.HIGHEST_PROTOCOL
3939
def _dumps(object, protocol):
4040
return pickle.dumps(object, protocol=protocol)
41-
from UserDict import DictMixin
41+
from collections import MutableMapping
4242
else:
4343
HIGHEST_PROTOCOL = None
4444
def _dumps(object, protocol):
4545
return pickle.dumps(object, bin=protocol)
46-
class DictMixin: pass
46+
class MutableMapping: pass
4747

4848
from . import db
4949

Lib/dumbdbm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323

2424
import io as _io
2525
import os as _os
26-
import UserDict
26+
import collections
2727

2828
_BLOCKSIZE = 512
2929

3030
error = IOError # For anydbm
3131

32-
class _Database(UserDict.DictMixin):
32+
class _Database(collections.MutableMapping):
3333

3434
# The on-disk directory and data files can remain in mutually
3535
# inconsistent states for an arbitrarily long time (see comments

Lib/shelve.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@
5959
from pickle import Pickler, Unpickler
6060
from io import BytesIO
6161

62-
import UserDict
62+
import collections
6363
import warnings
6464

6565
__all__ = ["Shelf","BsdDbShelf","DbfilenameShelf","open"]
6666

67-
class Shelf(UserDict.DictMixin):
67+
class Shelf(collections.MutableMapping):
6868
"""Base class for shelf implementations.
6969
7070
This is initialized with a dictionary-like object.
@@ -81,7 +81,7 @@ def __init__(self, dict, protocol=None, writeback=False,
8181
self.cache = {}
8282
self.keyencoding = "utf-8"
8383

84-
def keys(self):
84+
def __iter__(self):
8585
for k in self.dict.keys():
8686
yield k.decode(self.keyencoding)
8787

0 commit comments

Comments
 (0)