Skip to content

bpo-22671: Clarify and test default read method implementations#4568

Merged
vstinner merged 2 commits into
python:masterfrom
CuriousLearner:fix-issue22671
Dec 11, 2017
Merged

bpo-22671: Clarify and test default read method implementations#4568
vstinner merged 2 commits into
python:masterfrom
CuriousLearner:fix-issue22671

Conversation

@CuriousLearner

@CuriousLearner CuriousLearner commented Nov 26, 2017

Copy link
Copy Markdown
Member

This patch is by @vadmium . I take no credits for this.

I've applied it on the top of the master branch.

https://bugs.python.org/issue22671

@vstinner

Copy link
Copy Markdown
Member

This patch is by @vadmium . I take no credits for this.

In this case, you can specify the author when you do the Git commit. To modify the author of an existing author:

git commit --author='Martin Panter <vadmium+py@gmail.com>' --amend

@vstinner

Copy link
Copy Markdown
Member

I don't think that a NEWS entry is needed here: I added the "skip news" label.

@CuriousLearner

Copy link
Copy Markdown
Member Author

@vstinner I've updated the PR and marked @vadmium as the author for the commit. Let me know if there is any more help needed with this patch.

@vstinner vstinner 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.

The doc change LGTM, but I have requests on the newly added tests.

Comment thread Lib/test/test_io.py Outdated
def test_RawIOBase_read(self):
# Exercise the default RawIOBase.read() implementation (which calls
# readinto() internally).
# Exercise the default limited RawIOBase.read() implementation (which

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 dislike "limited", I would prefer to write read(n) for "limited", and read() for "unlimited".

Comment thread Lib/test/test_io.py
)
for test in tests:
with self.subTest(test):
method, avail, request, result = test

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.

Can you try to compute result from avail and request? result = min(avail, result, 5), no?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

+1, we can do that. But I was thinking that expected_read_size when mentioned explicitly as it is done right now, would be better for future reference.

Comment thread Lib/test/test_io.py
def test_BufferedIOBase_readinto(self):
# Exercise the default BufferedIOBase.readinto() and readinto1()
# implementations (which call read() or read1() internally).
class Reader(self.BufferedIOBase):

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.

Can you add an init() method taking avail as a parameter?

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.

Done

Comment thread Lib/test/test_io.py Outdated
method, avail, request, result = test
reader = Reader()
reader.avail = bytes(range(avail))
buffer = bytearray((0x81,) * request)

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.

Please use a constant instead of 0x81, like:

UNUSED_BYTE = 0x81

(define in this function, no need to declare it at the module scope.)

@vstinner vstinner merged commit 1b74f9b into python:master Dec 11, 2017
@vstinner

Copy link
Copy Markdown
Member

Oh, GitHub merged the two commits into a single one and chose to use Sanyam Khurana as the author. Hopefully, I wrote both names in the commit message ;-) (I edited manually the commit message before merging.)

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @CuriousLearner for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 11, 2017
…onGH-4568)

Original patch written by Martin Panter, enhanced by Sanyam Khurana.
(cherry picked from commit 1b74f9b)
@bedevere-bot

Copy link
Copy Markdown

GH-4796 is a backport of this pull request to the 3.6 branch.

vstinner pushed a commit that referenced this pull request Dec 11, 2017
) (#4796)

Original patch written by Martin Panter, enhanced by Sanyam Khurana.
(cherry picked from commit 1b74f9b)
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.

6 participants