summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2022-01-26 15:46:48 (GMT)
committerGitHub <noreply@github.com>2022-01-26 15:46:48 (GMT)
commitac0c6e128cb6553585af096c851c488b53a6c952 (patch)
tree28ada0f6fa8c6fcd40e3b863c57651c5462c9348 /Lib
parent1e8a3a5579c9a96a45073b24d1af2dbe3039d366 (diff)
downloadcpython-ac0c6e128cb6553585af096c851c488b53a6c952.zip
cpython-ac0c6e128cb6553585af096c851c488b53a6c952.tar.gz
cpython-ac0c6e128cb6553585af096c851c488b53a6c952.tar.bz2
bpo-46527: allow calling enumerate(iterable=...) again (GH-30904)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_enumerate.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/test/test_enumerate.py b/Lib/test/test_enumerate.py
index 906bfc2..5cb54cf 100644
--- a/Lib/test/test_enumerate.py
+++ b/Lib/test/test_enumerate.py
@@ -128,6 +128,18 @@ class EnumerateTestCase(unittest.TestCase, PickleTest):
self.assertRaises(TypeError, self.enum, 'abc', 'a') # wrong type
self.assertRaises(TypeError, self.enum, 'abc', 2, 3) # too many arguments
+ def test_kwargs(self):
+ self.assertEqual(list(self.enum(iterable=Ig(self.seq))), self.res)
+ expected = list(self.enum(Ig(self.seq), 0))
+ self.assertEqual(list(self.enum(iterable=Ig(self.seq), start=0)),
+ expected)
+ self.assertEqual(list(self.enum(start=0, iterable=Ig(self.seq))),
+ expected)
+ self.assertRaises(TypeError, self.enum, iterable=[], x=3)
+ self.assertRaises(TypeError, self.enum, start=0, x=3)
+ self.assertRaises(TypeError, self.enum, x=0, y=3)
+ self.assertRaises(TypeError, self.enum, x=0)
+
@support.cpython_only
def test_tuple_reuse(self):
# Tests an implementation detail where tuple is reused
@@ -266,14 +278,16 @@ class EnumerateStartTestCase(EnumerateTestCase):
class TestStart(EnumerateStartTestCase):
+ def enum(self, iterable, start=11):
+ return enumerate(iterable, start=start)
- enum = lambda self, i: enumerate(i, start=11)
seq, res = 'abc', [(11, 'a'), (12, 'b'), (13, 'c')]
class TestLongStart(EnumerateStartTestCase):
+ def enum(self, iterable, start=sys.maxsize + 1):
+ return enumerate(iterable, start=start)
- enum = lambda self, i: enumerate(i, start=sys.maxsize+1)
seq, res = 'abc', [(sys.maxsize+1,'a'), (sys.maxsize+2,'b'),
(sys.maxsize+3,'c')]