From 6abfc3a00c78511097ff6ea1e06a30ea53e0169b Mon Sep 17 00:00:00 2001 From: Chris Moradi <37349208+chrismoradi@users.noreply.github.com> Date: Mon, 25 Oct 2021 22:41:59 -0700 Subject: [PATCH] Revert UserDict.__init__ changes, new passing test of UserList --- Lib/collections/__init__.py | 19 +++++++++++++++++-- Lib/test/test_userlist.py | 2 -- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 25d1db7f9..ace8db113 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -1073,11 +1073,26 @@ class ChainMap(_collections_abc.MutableMapping): class UserDict(_collections_abc.MutableMapping): # Start by filling-out the abstract methods - def __init__(self, dict=None, /, **kwargs): + 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)) + if args: + dict = args[0] + elif 'dict' in kwargs: + dict = kwargs.pop('dict') + import warnings + warnings.warn("Passing 'dict' as keyword argument is deprecated", + DeprecationWarning, stacklevel=2) + else: + dict = None self.data = {} if dict is not None: self.update(dict) - if kwargs: + if len(kwargs): self.update(kwargs) def __len__(self): diff --git a/Lib/test/test_userlist.py b/Lib/test/test_userlist.py index 26752353a..3b30cdc8e 100644 --- a/Lib/test/test_userlist.py +++ b/Lib/test/test_userlist.py @@ -27,8 +27,6 @@ class UserListTest(list_tests.CommonTest): for j in range(-3, 6): self.assertEqual(u[i:j], l[i:j]) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_slice_type(self): l = [0, 1, 2, 3, 4] u = UserList(l)