bpo-32321: Add pure Python fallback for functools.reduce#9884
bpo-32321: Add pure Python fallback for functools.reduce#9884bradengroom wants to merge 5 commits into
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
| def reduce(function, iterable, initializer=None): | ||
| it = iter(iterable) | ||
| if initializer is None: | ||
| value = next(it) |
There was a problem hiding this comment.
This raises StopIteration when it should raise TypeError: reduce() of empty sequence with no initial value
|
@eric-wieser Realized I was missing some other pieces here. My fixup commit tests the new implementation as well as the C module. It also should raise the same exceptions as the C implementation now. |
| try: | ||
| iterable = iter(iterable) | ||
| except TypeError as err: | ||
| raise TypeError('reduce() arg 2 must support iteration') |
There was a problem hiding this comment.
| raise TypeError('reduce() arg 2 must support iteration') | |
| raise TypeError('reduce() arg 2 must support iteration') from None |
You don't want the first TypeError to show up in the traceback
| try: | ||
| value = next(iterable) | ||
| except StopIteration: | ||
| raise TypeError("reduce() of empty sequence with no initial value") |
There was a problem hiding this comment.
| raise TypeError("reduce() of empty sequence with no initial value") | |
| raise TypeError("reduce() of empty sequence with no initial value") from None |
See above
|
@rhettinger This is ready for core review. It looks like you are a code owner for this file. What's the proper way to ping for review? |
|
Oh. I wasn't aware that there were two PRs implementing the same thing. Sorry, I just merged the PR #8548. |
|
Oh I missed the other PR in the issue tracker somehow. Thanks |
https://bugs.python.org/issue32321