-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Conversation
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 |
@dongwooklee96 is the first-time contributor to the PyCon KR sprint today. |
11eb1ee
to
4fa459b
Compare
dongwooklee96, could you avoid force pushing? https://devguide.python.org/getting-started/pull-request-lifecycle:
|
tmp = list(islice(it, self._BATCHSIZE)) | ||
n = len(tmp) | ||
if n > 1: | ||
for batch in batched(items, self._BATCHSIZE): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Sure, I understand. I won’t force-push from now on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 👍
itertools.batched()
#126317