Skip to content

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

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
dongwooklee96:gh-126317
Nov 2, 2024
Merged

gh-126317: Simplify stdlib code by using itertools.batched()#126323
serhiy-storchaka merged 2 commits into
python:mainfrom
dongwooklee96:gh-126317

Conversation

@dongwooklee96

@dongwooklee96 dongwooklee96 commented Nov 2, 2024

Copy link
Copy Markdown
Contributor

@ghost

ghost commented Nov 2, 2024

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app

bedevere-app Bot commented Nov 2, 2024

Copy link
Copy Markdown

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

corona10 commented Nov 2, 2024

Copy link
Copy Markdown
Member

@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 :)

Comment thread Lib/pickle.py Outdated
Comment thread Lib/pickle.py Outdated
Comment thread Lib/pickle.py Outdated
Comment thread Lib/pickle.py Outdated
Comment thread Lib/pickle.py Outdated
Comment thread Lib/pickle.py Outdated
Comment thread Lib/pickle.py Outdated
@nineteendo

Copy link
Copy Markdown
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.

Comment thread Lib/pickle.py Outdated
Comment thread Lib/pickle.py
tmp = list(islice(it, self._BATCHSIZE))
n = len(tmp)
if n > 1:
for batch in batched(items, self._BATCHSIZE):

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.

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

Copy link
Copy Markdown
Member

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
Copy Markdown
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?

@picnixz picnixz Nov 2, 2024

Copy link
Copy Markdown
Member

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"

Comment thread Lib/pickle.py
if len(batch) != 1:
write(MARK)
for i, x in enumerate(tmp, start):
for i, x in enumerate(batch, start):

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.

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

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. 👍

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