gh-126317: Simplify stdlib code by using itertools.batched()#126323
gh-126317: Simplify stdlib code by using itertools.batched()#126323serhiy-storchaka merged 2 commits intopython:mainfrom
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.
Is it worth using tmp instead of batch? It reduces the diff, but feel free to disregard.
There was a problem hiding this comment.
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.
I also think chunk would be better, should we change it to chunk?
There was a problem hiding this comment.
Since we use "batchsize" I think it's fine to keep "batch"
| if len(batch) != 1: | ||
| write(MARK) | ||
| for i, x in enumerate(tmp, start): | ||
| for i, x in enumerate(batch, start): |
There was a problem hiding this comment.
Is it faster to calculate start + i in case of an error?
There was a problem hiding this comment.
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. |
itertools.batched()#126317