summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_list.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_list.py')
-rw-r--r--Lib/test/test_list.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py
index 3c8d829..d3da05b 100644
--- a/Lib/test/test_list.py
+++ b/Lib/test/test_list.py
@@ -46,6 +46,34 @@ class ListTest(list_tests.CommonTest):
with self.assertRaisesRegex(TypeError, 'keyword argument'):
list(sequence=[])
+ def test_keywords_in_subclass(self):
+ class subclass(list):
+ pass
+ u = subclass([1, 2])
+ self.assertIs(type(u), subclass)
+ self.assertEqual(list(u), [1, 2])
+ with self.assertRaises(TypeError):
+ subclass(sequence=())
+
+ class subclass_with_init(list):
+ def __init__(self, seq, newarg=None):
+ super().__init__(seq)
+ self.newarg = newarg
+ u = subclass_with_init([1, 2], newarg=3)
+ self.assertIs(type(u), subclass_with_init)
+ self.assertEqual(list(u), [1, 2])
+ self.assertEqual(u.newarg, 3)
+
+ class subclass_with_new(list):
+ def __new__(cls, seq, newarg=None):
+ self = super().__new__(cls, seq)
+ self.newarg = newarg
+ return self
+ u = subclass_with_new([1, 2], newarg=3)
+ self.assertIs(type(u), subclass_with_new)
+ self.assertEqual(list(u), [1, 2])
+ self.assertEqual(u.newarg, 3)
+
def test_truth(self):
super().test_truth()
self.assertTrue(not [])