Skip to content

bpo-32321: Add pure Python fallback for functools.reduce#9884

Closed
bradengroom wants to merge 5 commits into
python:masterfrom
bradengroom:issue-32321
Closed

bpo-32321: Add pure Python fallback for functools.reduce#9884
bradengroom wants to merge 5 commits into
python:masterfrom
bradengroom:issue-32321

Conversation

@bradengroom

@bradengroom bradengroom commented Oct 14, 2018

Copy link
Copy Markdown
Contributor

@the-knights-who-say-ni

Copy link
Copy Markdown

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!

Comment thread Lib/functools.py Outdated
def reduce(function, iterable, initializer=None):
it = iter(iterable)
if initializer is None:
value = next(it)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raises StopIteration when it should raise TypeError: reduce() of empty sequence with no initial value

@bradengroom

Copy link
Copy Markdown
Contributor Author

@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.

Comment thread Lib/functools.py Outdated
try:
iterable = iter(iterable)
except TypeError as err:
raise TypeError('reduce() arg 2 must support iteration')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment thread Lib/functools.py Outdated
try:
value = next(iterable)
except StopIteration:
raise TypeError("reduce() of empty sequence with no initial value")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise TypeError("reduce() of empty sequence with no initial value")
raise TypeError("reduce() of empty sequence with no initial value") from None

See above

@bradengroom

Copy link
Copy Markdown
Contributor Author

@pppery Thanks
63bfc75

@bradengroom

Copy link
Copy Markdown
Contributor Author

@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?

@vstinner

Copy link
Copy Markdown
Member

Oh. I wasn't aware that there were two PRs implementing the same thing. Sorry, I just merged the PR #8548.

@vstinner vstinner closed this Oct 25, 2018
@bradengroom

Copy link
Copy Markdown
Contributor Author

Oh I missed the other PR in the issue tracker somehow. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants