changeset: 93622:167d51a54de2 parent: 93620:88ab046fdd8a parent: 93621:cd1ead4feddf user: Serhiy Storchaka date: Thu Nov 27 17:46:15 2014 +0200 files: Lib/collections/__init__.py Lib/test/test_collections.py description: Issue #22609: Revert changes in UserDict. They conflicted with existing tests. diff -r 88ab046fdd8a -r 167d51a54de2 Lib/collections/__init__.py --- a/Lib/collections/__init__.py Thu Nov 27 16:35:26 2014 +0200 +++ b/Lib/collections/__init__.py Thu Nov 27 17:46:15 2014 +0200 @@ -922,14 +922,7 @@ class UserDict(MutableMapping): # Start by filling-out the abstract methods - def __init__(*args, **kwargs): - if not args: - raise TypeError("descriptor '__init__' of 'UserDict' object " - "needs an argument") - self, *args = args - if len(args) > 1: - raise TypeError('expected at most 1 arguments, got %d' % len(args)) - dict = args[0] if args else None + def __init__(self, dict=None, **kwargs): self.data = {} if dict is not None: self.update(dict) diff -r 88ab046fdd8a -r 167d51a54de2 Lib/test/test_collections.py --- a/Lib/test/test_collections.py Thu Nov 27 16:35:26 2014 +0200 +++ b/Lib/test/test_collections.py Thu Nov 27 17:46:15 2014 +0200 @@ -1639,24 +1639,6 @@ d = self._empty_mapping() self.assertRaises(KeyError, d.popitem) -class TestUserDict(unittest.TestCase): - - def test_init(self): - self.assertEqual(list(UserDict(self=42).items()), [('self', 42)]) - self.assertEqual(list(UserDict(dict=42).items()), [('dict', 42)]) - self.assertEqual(list(UserDict(dict=None).items()), [('dict', None)]) - self.assertRaises(TypeError, UserDict, 42) - self.assertRaises(TypeError, UserDict, (), ()) - self.assertRaises(TypeError, UserDict.__init__) - - def test_update(self): - d = UserDict() - d.update(self=42) - self.assertEqual(list(d.items()), [('self', 42)]) - self.assertRaises(TypeError, UserDict().update, 42) - self.assertRaises(TypeError, UserDict().update, {}, {}) - self.assertRaises(TypeError, UserDict.update) - ################################################################################ ### Run tests @@ -1668,8 +1650,7 @@ NamedTupleDocs = doctest.DocTestSuite(module=collections) test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs, TestCollectionABCs, TestCounter, TestChainMap, - TestOrderedDict, GeneralMappingTests, SubclassMappingTests, - TestUserDict,] + TestOrderedDict, GeneralMappingTests, SubclassMappingTests] support.run_unittest(*test_classes) support.run_doctest(collections, verbose)