Issue #22609: Revert changes in UserDict. They conflicted with existing tests.
This commit is contained in:
parent
ae5cb214d2
commit
a86700ae87
|
@ -893,14 +893,7 @@ class ChainMap(MutableMapping):
|
||||||
class UserDict(MutableMapping):
|
class UserDict(MutableMapping):
|
||||||
|
|
||||||
# Start by filling-out the abstract methods
|
# Start by filling-out the abstract methods
|
||||||
def __init__(*args, **kwargs):
|
def __init__(self, dict=None, **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
|
|
||||||
self.data = {}
|
self.data = {}
|
||||||
if dict is not None:
|
if dict is not None:
|
||||||
self.update(dict)
|
self.update(dict)
|
||||||
|
|
|
@ -1571,24 +1571,6 @@ class SubclassMappingTests(mapping_tests.BasicTestMappingProtocol):
|
||||||
d = self._empty_mapping()
|
d = self._empty_mapping()
|
||||||
self.assertRaises(KeyError, d.popitem)
|
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
|
### Run tests
|
||||||
|
@ -1600,8 +1582,7 @@ def test_main(verbose=None):
|
||||||
NamedTupleDocs = doctest.DocTestSuite(module=collections)
|
NamedTupleDocs = doctest.DocTestSuite(module=collections)
|
||||||
test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs,
|
test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs,
|
||||||
TestCollectionABCs, TestCounter, TestChainMap,
|
TestCollectionABCs, TestCounter, TestChainMap,
|
||||||
TestOrderedDict, GeneralMappingTests, SubclassMappingTests,
|
TestOrderedDict, GeneralMappingTests, SubclassMappingTests]
|
||||||
TestUserDict,]
|
|
||||||
support.run_unittest(*test_classes)
|
support.run_unittest(*test_classes)
|
||||||
support.run_doctest(collections, verbose)
|
support.run_doctest(collections, verbose)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue