cpython: 3dfe4f0c626b (original) (raw)

--- a/Lib/_abcoll.py +++ b/Lib/_abcoll.py @@ -548,23 +548,25 @@ class MutableMapping(Mapping): If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v '''

-

--- a/Lib/collections.py +++ b/Lib/collections.py @@ -35,12 +35,17 @@ class OrderedDict(dict): # The sentinel element never gets deleted (this simplifies the algorithm). # Each link is stored as a list of length three: [PREV, NEXT, KEY].

'''

@@ -438,7 +443,7 @@ class Counter(dict): # http://code.activestate.com/recipes/259174/[](#l2.23) # Knuth, TAOCP Vol. II section 4.6.3

@@ -449,8 +454,15 @@ class Counter(dict): >>> c = Counter(a=4, b=2) # a new counter from keyword args '''

def missing(self, key): 'The count of elements not in the Counter is zero.' @@ -501,7 +513,7 @@ class Counter(dict): raise NotImplementedError( 'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')

Source can be an iterable, a dictionary, or another Counter instance. @@ -521,6 +533,14 @@ class Counter(dict): # contexts. Instead, we implement straight-addition. Both the inputs # and outputs are allowed to contain zero and negative counts.

@@ -536,7 +556,7 @@ class Counter(dict): if kwds: self.update(kwds)

@@ -552,6 +572,14 @@ class Counter(dict): -1 '''

--- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -905,6 +905,28 @@ class TestCounter(unittest.TestCase): self.assertEqual(c.setdefault('e', 5), 5) self.assertEqual(c['e'], 5)

+

+ def test_copying(self): # Check that counters are copyable, deepcopyable, picklable, and #have a repr/eval round-trip @@ -1006,6 +1028,16 @@ class TestCounter(unittest.TestCase): c.subtract('aaaabbcce') self.assertEqual(c, Counter(a=-1, b=0, c=-1, d=1, e=-1))

+ class TestOrderedDict(unittest.TestCase): def test_init(self): @@ -1019,8 +1051,11 @@ class TestOrderedDict(unittest.TestCase) c=3, e=5).items()), pairs) # mixed input # make sure no positional args conflict with possible kwdargs

# Make sure that direct calls to init do not clear previous contents d = OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 44), ('e', 55)]) @@ -1065,6 +1100,10 @@ class TestOrderedDict(unittest.TestCase) self.assertEqual(list(d.items()), [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 6), ('g', 7)])

+ def test_abc(self): self.assertIsInstance(OrderedDict(), MutableMapping) self.assertTrue(issubclass(OrderedDict, MutableMapping))

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,9 @@ Core and Builtins Library ------- +- Issue #22609: Constructors and update methods of mapping classes in the