Skip to content
This repository was archived by the owner on Mar 10, 2025. It is now read-only.

Commit 99d6a2d

Browse files
committed
Handle reduction of empty iterable without initial value using Python 3.10
1 parent 2867faf commit 99d6a2d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/pyby/enumerable.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
from itertools import islice
33
from .object import RObject
44

5+
EMPTY_REDUCE_ERRORS = [
6+
"reduce() of empty sequence with no initial value",
7+
"reduce() of empty iterable with no initial value",
8+
]
9+
510

611
class Enumerable(RObject):
712
"""
@@ -89,7 +94,7 @@ def inject(self, *args):
8994
else:
9095
return functools.reduce(args[1], self.__each__(), args[0])
9196
except TypeError as error:
92-
if error.args[0] == "reduce() of empty sequence with no initial value":
97+
if error.args[0] in EMPTY_REDUCE_ERRORS:
9398
return None
9499
else:
95100
raise

0 commit comments

Comments
 (0)