Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-126317: Simplify stdlib code by using itertools.batched() #126323

Merged
merged 2 commits into from
Nov 2, 2024

Conversation

dongwooklee96
Copy link
Contributor

@dongwooklee96 dongwooklee96 commented Nov 2, 2024

Copy link

cpython-cla-bot bot commented Nov 2, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Nov 2, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@corona10
Copy link
Member

corona10 commented Nov 2, 2024

@serhiy-storchaka

@dongwooklee96 is the first-time contributor to the PyCon KR sprint today.
I am not sure if this change is worth accepting from my side.
So I am delegating the review to you :)

Lib/pickle.py Outdated Show resolved Hide resolved
Lib/pickle.py Outdated Show resolved Hide resolved
Lib/pickle.py Outdated Show resolved Hide resolved
Lib/pickle.py Outdated Show resolved Hide resolved
Lib/pickle.py Outdated Show resolved Hide resolved
Lib/pickle.py Outdated Show resolved Hide resolved
Lib/pickle.py Outdated Show resolved Hide resolved
@nineteendo
Copy link
Contributor

dongwooklee96, could you avoid force pushing? https://devguide.python.org/getting-started/pull-request-lifecycle:

In order to keep the commit history intact, please avoid squashing or amending history and then force-pushing to the PR. Reviewers often want to look at individual commits.

Lib/pickle.py Outdated Show resolved Hide resolved
tmp = list(islice(it, self._BATCHSIZE))
n = len(tmp)
if n > 1:
for batch in batched(items, self._BATCHSIZE):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth using tmp instead of batch? It reduces the diff, but feel free to disregard.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to have a named variable that says what it is. "tmp" is too generic IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also think chunk would be better, should we change it to chunk?

Copy link
Contributor

@picnixz picnixz Nov 2, 2024

Choose a reason for hiding this comment

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

Since we use "batchsize" I think it's fine to keep "batch"

write(MARK)
for i, x in enumerate(tmp, start):
for i, x in enumerate(batch, start):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it faster to calculate start + i in case of an error?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably faster because we don't need to materialize an enumerate object but I'd benchmark that one to be sure.

@dongwooklee96
Copy link
Contributor Author

dongwooklee96, could you avoid force pushing? https://devguide.python.org/getting-started/pull-request-lifecycle:

In order to keep the commit history intact, please avoid squashing or amending history and then force-pushing to the PR. Reviewers often want to look at individual commits.

Sure, I understand. I won’t force-push from now on.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

@serhiy-storchaka serhiy-storchaka merged commit bd4be5e into python:main Nov 2, 2024
38 checks passed
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.

5 participants