GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-90533: Implement BytesIO.peek() by marcelm · Pull Request #150917 · python/cpython Conversation
|
|
CI all green! :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| .. method:: peek(size=0, /) | ||
|
|
||
| Return bytes from the current position onwards without advancing the position. | ||
| At least one byte of data is returned if not at EOF. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The size=0 case is not well documented. It's unclear to me when I read the doc if peek() or peek(0) return an empty string or something else.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I’ve updated the documentation. I also changed the wording to make it clearer that a copy is returned, which I think is good to point out because a copy could potentially be costly.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| Return a copy of the buffer from the current position onwards without advancing the position. | ||
|
|
||
| If *size* is zero or omitted, the returned :class:`bytes` object extends to EOF. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
At least, the Python implementation limits the returned string to io.DEFAULT_BUFFER_SIZE bytes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I have removed the limit even in the Python implementation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think it would still be good to default limit. That way if there's a 1GB BytesIO and you .peek() you don't copy all that data... more just document more precisely.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I misremembered what was said earlier. I will fix it next week.
Should maybe the the signature be changed to peek(size=DEFAULT_BUFFER_SIZE)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I still prefer 0 as a default, differentiating between "unspecified" and "exactly this size".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Hum, I see multiple discussions about
If the IMO limiting |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I have updated the behavior such that at most Maybe for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the updates.
@cmaloney: Would you mind to double check the change?
Maybe for size=-1, the behavior could be that the full remainder of the buffer is returned, but I don’t mind either way.
If you know that the file is smaller than available memory, you can pass sys.maxsize :-)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Ideally this would use PEP-661 so we could distinguish the cases "not provided" and "all" easily but the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Cody Maloney <[email protected]>
|
@marcelm: Can you please update your PR and solve the merge conflict on Doc/whatsnew/3.16.rst? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Updated (The lzma whatsnew entry moved to be alphabetical / after logging) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Congrats @marcelm! Finally, I merged your PR! Sorry for all the back and forth, but it was really hard to decide on the exact API, especially for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Oh, nice, happy to see this go in just before going on vacation! 😄 I think what was a bit difficult was that it was hard to tell who gets to decide, that is, whose requests I should implement if there was a disagreement (between core devs). This was also the reason for the long delay between Nov. 2023 and then April this year. I’m glad it worked out now, even if it took ~180 comments and 54 commits for a ~200 line change. Thanks everyone for your help, I learned a lot along the way! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
That's a very long history. Thanks for your tenacity :-D |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for all the work @marcelm! Noted on the decision and debate parts. Really appreciate working through it and think we ended up with a really nice new feature :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
io.BytesIO does not have peek()
There was an error while loading. Please reload this page.